Write a program that validates time when entered

Assignment Help JAVA Programming
Reference no: EM131030451

Assignment

Comments are REQUIRED; flow charts and pseudocode are NOT REQUIRED.

Directions

The files must be called <LiFiUnit6Ch15.java>

LiFiTime.java (Time class file)

The files must be called as specified above, (LiFi = Your Last Initial Your First Initial)

Proper coding conventions required the first letter of the class start with a capital letter and the first letter of each additional word start with a capital letter.

Only submit the .java files needed to make the program run. Do not submit the class files or any other files.

Style Components

Include properly formatted prologue, comments, indenting, and other style elements as shown in Chapter 2 starting page 64 and Appendix 5 page 881-892.

Topics covered in chapter

Topics with * are covered in this assignment.

*Exceptions and Exception Messages
*try / catch
*checked and unchecked exceptions
*generic catch block
*throws

Basic Requirements

Write a program that validates time when entered. It should output the time as either AM or PM or the error if entered incorrectly.

See sample output below.

LiFiUnit6Ch15.java

• Driver class should loop until "q" is entered to quit
• If enter is not "q", then create an instance of the LiFiTime object passing the entry as an argument
• If no error

o Print time by calling print method in LiFiTime class
• If error
o Print error message (see sample)

LiFiTime.java class

Time objects should store the time in 2 integer instance variables, hour and minute, and include a string variable to hold the error. This should be initialized with null.

LiFiTime Constructor:

• Receive time as a string
• Perform error checking to ensure time was entered in proper format to include a color (:) between the digits
• Use indexOf and substring to separate the time string into the appropriate instance variables
• Check hour to ensure is between 1 and 23
• Check minute to ensure is between 0 and 59
• If an error occurs, change the error instance variable to reflect the error (see sample)

print method:

• Include a separate method to print the date using printf to output time in digits for the hour and 2 digits for the minutes
• Print AM if before noon and PM if after noon. Do NOT print in military time

getError method:
• Include a getError method that returns the error instance variable to the print method

NOTE: Complete your activity and submit it by clicking "Submit Assignment"

Sample

Your output will vary based on the random numbers generated.

Sample session (requires no user input):
Enter time in the form mm:dd ("q" to quit): 5:20
05:20 AM
Enter time in the form mm:dd ("q" to quit): 05:20
05:20 AM
Enter time in the form mm:dd ("q" to quit): 05:80
Invalid minute entered: 80

Enter time in the form mm:dd ("q" to quit): 15:20
03:20 PM
Enter time in the form mm:dd ("q" to quit): 25:20
Invalid hour entered: 25
Enter time in the form mm:dd ("q" to quit): 0520
Invalid separator entered: :
Enter time in the form mm:dd ("q" to quit): q

Reference no: EM131030451

Questions Cloud

Discuss artistic elements that characterize book of kells p : Discuss Artistic elements that characterize the Book of Kells. P.
What laws apply to web contracts : What laws apply to web contracts? What laws apply to web contracts?
How the political divide would evolve into two-party system : By choosing this option, you will write out your speech in essay form. Using these four bullets you have selected summarize how this political divide would evolve into the two-party system.
Tort cases for medical malpractice : What is the standard of review regarding tort cases for medical malpractice?
Write a program that validates time when entered : Write a program that validates time when entered. It should output the time as either AM or PM or the error if entered incorrectly.
The exploitation of his image via english tort law : How can a musician prevent the exploitation of his image via english tort law?
Describe what jurisdiction : Describe what jurisdiction is. Use your local community and provide an example of your courthouse's jurisdiction. How can a court gain jurisdiction over a person, or subject matter in your venue or local area?
How did the group know when a decision had been made : What decisions were made? How did the group know when a decision had been made? For instance, did the group use some form of parliamentary procedure or did it come to consensus? If it used consensus, who stated the group consensus? Was there a pl..
What are an agent''s duties to his principal employer : What are an agent's duties to his principal employer?

Reviews

Write a Review

JAVA Programming Questions & Answers

  Development of a graphical user interface

To understand actual communication with an SMTP server can be achieved using TCP Sockets and understand the development of a graphical user interface (GUI) and use of event handling.

  Draw a picture with an appearance

You must use the given Rectangle and Oval classes to draw a picture with an appearance as close as possible.

  You must also do the work of sorting

You must also do the work of sorting in the method. You cannot just call another library method. Use loops to show the data in the original array as well as the repopulated array in ascending order.

  Displays the number of days in a month

Create a program that displays the number of days in a month. Use a 12-element one-dimensional array to store the number of days in each month (use 28 for the number of days in February).

  Prepare demo program that implements all of above method

Specify, design, and implement a class that can be used in a program that simulates a combination lock.

  Implement a class called shortaddress

inally write an application class to allow the user to input an address details and then give the user the choice of viewing the short address details or the long address details. This means your final answer should have a minimum of 3 classes for..

  Your taskbullthe auction system should allow the user to

your taskbullthe auction system should allow the user to participate in a number of items and for the user to be able

  Multiple inheritance and thunks

Then, pa and pc will contain the same value, but pb will contain a different value; it will contain the address of the B part of the C object. The fact that pb and pc do not contain the same value means that in C++, a cast sometimes has a run-time..

  Default constructor for the chatioexception class.

The second constructor takes in a string as a parameter and passes this string into the call to super();

  Java program to demonstrate the use of jdbc

Write a Java program (non-GUI preferred) to demonstrate the use of JDBC. Write a list of animal and its characteristics to a database using JDBC

  Write a java program that would simulate a number of cars

Write a JAVA program that would simulate a number of cars' (e.g. 4) speed meter using the concept of Multithreading. A car's speed can be both increased and decreased using specified keys from the keyboard

  Class diagram represents the relationship between parents

Draw a class diagram that represents the relationship between parents, children, and grandparents. Take into account that a person can have both a parent and a child. Annotate associations with roles and multiplicities.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd