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

  User session mgr - socket and thread programs

User Session Mgr - Socket and Thread Programs

  Create the look for two gui applications

Create the look for two GUI applications. You WILL NOT be getting the applications to do anything. We are only interested in seeing how well you can arrange the GUI components onto the window

  The federal acquisition regulation

According to the text, the Federal Acquisition Regulation (FAR) is a body of law that governs U.S. Federal Government's procurement process. The FAR is prepared, issued and maintained under the joint command of the Secretary of Defense, the Administr..

  Explain the legal doctrine benefits balancing

Explain the legal doctrine "Benefits Balancing" as it pertains to applying the reasonable standard of care doctrine in the medical fields. Does a defense that the majority of physicians normally do not give a particular diagnostic test in the normal ..

  Write java program to print strings given at command line

Write a program Average.java which just prints strings that it is given at command line, one per line. If nothing is given at command line, print "No arguments".

  Java shape program console

Program is adequately documented. It's comments identifies its name, purpose, author and date.Throughout the code, comments and/or relevant component names should attempt to make theprogram understandable.

  Mvc pattern and servlet

When you use the MVC pattern, the controller directs the flow of control to

  Are scripting languages such as javascript better choice

Based on Keston (2008), does the C++ programming language have a role in developing Web 2.0 application solutions based on service-oriented architectures (SOA)? Explain why or why not. Are scripting languages such as JavaScript Perl or Python bett..

  Packer logo method

Being a super Packer fan's wife, this assignment involves the use of the Green Bay Packer logo. Any die-hard Minnesota fans are welcome to use the Viking's logo instead.

  Chat monitoring system

The name of the project is chat monitoring system. in the file you will see the screenshot diagram 2A are my design, i want it to be upgrade, to look professional like the diagram 2B. please java, netbeans and GUI. please can I have only the client s..

  Write a console program with java

Programming exercises are a key component of learning any programming language

  Implement a simple relational dbms

In Problem Set, you began to implement a simple relational DBMS by taking the code base that we gave you and adding support for INSERT commands and for SELECT * commands involving a single table.

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