Question

Java Store Time Clock Objects

1. Create a Time class which is designed to contain objects representing times in 12-hour clock format. Eg: 6:58am, 11:13pm, 12:00am (= midnight), 12:00pm (= noon). You can assume the user will enter times in the format given by the previous examples.

Provide a default constructor, a set method which is given a String (eg: “9:42am”), a getHours method, a getMinutes method and a boolean isAm method. Also provide a method for returning a string “morning”, “afternoon”, “evening” or “night” appropriate (in your opinion) to the time.

Please see the NOTE below concerning input validation and exception.

2. Write a client program for Time which loops around getting strings from the user representing times and responding with a greeting such as “good morning” as appropriate. The user should enter the string “quit” to exit the program.

EXAMPLE run of client:

USER: 1:47 pm
PROGRAM: good afternoon

USER: 6:76 am
PROGRAM: INVALID TIME, RE-ENTER

USER: 14:19am
PROGRAM: INVALID TIME, RE-ENTER

USER: 10:03am
PROGRAM: good morning
USER: 7:00 pm
PROGRAM: good evening

NOTE for questions 1 and 2: the set method for Time should detect input strings which do not represent valid times. An exception should be thrown in such a case. Clients (such as the one you are writing for question 2) will have to handle (or catch) the exceptions. Thus you will have to also write your own exception class which can be used by Time and the client class.


0 0
Add a comment Improve this question Transcribed image text
Know the answer?
Add Answer to:
Java Store Time Clock Objects
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 1. Create a MyTime class which is designed to contain objects representing times in 12-hour clock...

    1. Create a MyTime class which is designed to contain objects representing times in 12-hour clock format. Eg: 7:53am, 10:20pm, 12:00am (= midnight), 12:00pm (= noon). You can assume the user will enter times in the format given by the previous examples. Provide a default constructor, a set method which is given a String (eg: “7:53am”), a getHours method, a getMinutes method and a boolean isAm method. Also provide a method for returning a string “morning”, “afternoon”, “evening” or “night”...

  • JAVA 1. Create a MyTime class which is designed to contain objects representing times in 12-hour...

    JAVA 1. Create a MyTime class which is designed to contain objects representing times in 12-hour clock like 7:53am, 10:20pm, 12:00am (= midnight), 12:00pm (= noon). Provide a default constructor, a set method which is given a String (eg, “7:53am”), a getHours method, a getMinutes method and a boolean isAm method. Also provide a method for returning a string “morning”, “afternoon”, “evening” or “night” appropriate (in your opinion) to the time. Please see the NOTE below concerning input validation and...

  • What to submit: your answers to exercises 1, and 2 and separate the codes to each...

    What to submit: your answers to exercises 1, and 2 and separate the codes to each question. Create a MyTime class which is designed to contain objects representing times in 12-hour clock format. Eg: 7:53am, 10:20pm, 12:00am (= midnight), 12:00pm (= noon). You can assume the user will enter times in the format given by the previous examples. Provide a default constructor, a set method which is given a String (eg: “7:53am”), a getHours method, a getMinutes method and a...

  • JAVA PROGRAM. Write a program to implement a class Clock whose getHours and getMinutes methods return the current time a...

    JAVA PROGRAM. Write a program to implement a class Clock whose getHours and getMinutes methods return the current time at your location. Also include a getTime method that returns a string with the hours and minutes by calling the getHours and getMinutes methods. Provide a subclass WorldClock whose constructor accepts a time offset. For example, if you livein California, a new WorldCLock(3) should show the time in NewYork, three time zones ahead. Include an Alarm feature in the Clock class....

  • For this project you will be writing up a simple Clock program to keep track of...

    For this project you will be writing up a simple Clock program to keep track of time. SimpleClock.java - contains your implementation of the SimpleClock class. You will need to provide the code for a constructor as well as the mutator methods set and tick and the accessor method toString. Look at the comments for each method to see how they should be implemented - the trickiest method is probably tick, which requires that you deal with the changing of...

  • Source material: Object-Oriented Data Structures Using Java, 3rd Edition by Nell Dale. What is the answer...

    Source material: Object-Oriented Data Structures Using Java, 3rd Edition by Nell Dale. What is the answer to exercise 13 in chapter 3 (page 232)?? "A. Create a "standard" exception class called ThirteenException. B. Write a program that repeatedly prompts the user to enter a string. After each string is entered the program outputs the length of the string, unless the length of the string is 13, in which case the ThirteenException is thrown with the message "Use thirteen letter words...

  • I am supposed to reduce redundancy in the code and also make unknown inputs, output "unknown"....

    I am supposed to reduce redundancy in the code and also make unknown inputs, output "unknown". Step 1: Your development manager likes your program but is concerned about code duplication. Roger left a note on your desk, asking about using a feature for automatically converting strings to enumerations. Change your ToCommand method to employ this JAVA library method. (Hint: Look for a valueOf method). After converting your ToCommand method, run the program and enter an invalid command (one that does...

  • create a new Java application called "CheckString" (without the quotation marks) according to the following guidelines....

    create a new Java application called "CheckString" (without the quotation marks) according to the following guidelines. ** Each method below, including main, should handle (catch) any Exceptions that are thrown. ** ** If an Exception is thrown and caught, print the Exception's message to the command line. ** Write a complete Java method called checkWord that takes a String parameter called word, returns nothing, and is declared to throw an Exception of type Exception. In the method, check if the...

  • need help with this JAVA lab, the starting code for the lab is below. directions: The...

    need help with this JAVA lab, the starting code for the lab is below. directions: The Clock class has fields to store the hours, minutes and meridian (a.m. or p.m.) of the clock. This class also has a method that compares two Clock instances and returns the one that is set to earlier in the day. The blahblahblah class has a method to get the hours, minutes and meridian from the user. Then a main method in that class creates...

  • Please write in dr java Here is the driver: import java.util.*; public class SquareDriver { public...

    Please write in dr java Here is the driver: import java.util.*; public class SquareDriver { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); String input =""; System.out.println("Welcome to the easy square program"); while(true) { System.out.println("Enter the length of the side of a square or enter QUIT to quit"); try { input = keyboard.nextLine(); if(input.equalsIgnoreCase("quit")) break; int length = Integer.parseInt(input); Square s = new Square(); s.setLength(length); s.draw(); System.out.println("The area is "+s.getArea()); System.out.println("The perimeter is "+s.getPerimeter()); } catch(DimensionException e)...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT