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

  Write a method, insertat that takes four parameters

Write a method, insertAt that takes four parameters

  User interface menu using doubly linked lists

Each mNode defines the main menu item name, two links to its mNode neighbors (the previous and next mNode) and a link to its first submenu node.

  What should a comment at the class level contain

How do you identify a comment so the Javadoc tool will recognize it and what should a comment at the class level contain?

  Write a class lines containing a static method

Write a class Lines containing a static method dashedLine to draw dashed lines, so it can write:

  Write down a java program and pseudocode to read a number

write a java program and pseudocode to read a number up to 15 digits long or a date ddmmyyyy. the program should

  What are some of the differences in the sql

What are some of the differences in the SQL supported by RDBMS vendors?

  Write a reference class called ctatrain

writing a reference class that consist of the 2nd and 3rd instance variables below. my class should consist of an array of values in the 2nd instance variable

  Explain what is set interface

In the java language, explain What is Set Interface?

  Print the number of lines the number of words

a java program where im supposed to print the number of lines the number of words and the longest line in a text file!

  Corrections as necessary and output screen snapshots

Submit all completed programs, with corrections as necessary and output screen snapshots, to demonstrate that they all perform properly to meet the specifications.

  Implement a program that will play the old guessing game

Your assignment is to implement a program that will play the old guessing game "I'm thinking of a number between 1 and 100". The program will be in a webpage

  What is the memory address of the first array location

What is an n-dimensional array? What does "n" refer to?

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