Create constructors use the same exception handling

Assignment Help Computer Engineering
Reference no: EM1330051

Need assistance with driver class and Date class. This is what I have so far for the driver class.
In the driver class, include a loop that repeatedly:
?Asks the user to enter a date or "q" to quit.
?If the entry is not "q", instantiate a Date object.
?If the error variable is null:
oPrint the date using numeric format.
oPrint the date using alphabetic format.
?Otherwise, print the value of the error variable.

Date objects should store the date in two int instance variables: day and month, and it should include the String instance variable, error, initialized with null.
Implement a 1-parameter Date constructor that receives a dateStr string parameter and performs complete error checking on the given dateStr value. The Date constructor is the entity that's responsible for date error checking. That way, if a Date object is instantiated and if there are no errors, then you're guaranteed that the Date object holds a legitimate date value. If any kind of error occurs, change the value of the error instance variable to a non-null string value, using an appropriate concatenation of a string constant, input substring, and/or API exception message.
Constructors use the same exception handling rules as methods: In a try block, include the parsing of the month and day substrings and other error-checking logic that will not work if parsing fails.
Take into account the actual number of days in each month, but assume that there are always 28 days in February.
To extract day and month numbers from the given date string, use String's indexOf method to find the location of the slash character, and String's substring method to extract month and day substrings from the input string.
Include a method for printing the date with a numeric format. Use the zero-pad flag in a printf method call to get exactly two digits for each month and day.
Include a method for printing the date with an alphabetic format.
Include a getError method which returns the value of the error instance variable.

Sample session:

Enter a date in the form mm/dd ("q" to quit): 5/2
05/02
May 2
Enter a date in the form mm/dd ("q" to quit): 05/02
05/02
May 2
Enter a date in the form mm/dd ("q" to quit): 52
Invalid date format - 52
Enter a date in the form mm/dd ("q" to quit): 5.0/2
Invalid format - For input string: "5.0"
Enter a date in the form mm/dd ("q" to quit): 13/2
Invalid month - 13
Enter a date in the form mm/dd ("q" to quit): 2/x
Invalid format - For input string: "x"
Enter a date in the form mm/dd ("q" to quit): 2/30
Invalid day - 30
Enter a date in the form mm/dd ("q" to quit): 2/28
02/28
February 28
Enter a date in the form mm/dd ("q" to quit): q

Reference no: EM1330051

Questions Cloud

Explain why is the internet important for business : Explain Why is the Internet important for business and present a powerpoint presentation on the changes the Internet has made in the way we do business across the world
Ordinary annuity and annuity due : Find out the future value of following annuities. The first payment in these annuities is made at the end of year one. That is, they're are ordinary annuities.
Describe eight key differences : Describe eight key differences between American style/custom and that particular country's style/custom in terms of aspects of speaking, meetings, meals, relationships, friendships, and communication that would impact business dealings.
Inflation affect an companys decision-making process : Explain how does inflation affect an company's decision-making process.
Create constructors use the same exception handling : Date objects must store the date in two int instance variables: day and month, and it has to include the String instance variable, error, initialized with null.
Examine the international business management : International Business Management: ABC Complete Kitchens, Inc - Analyzes the international management considerations associated with the plant
Illustrate what would this typical basket : Illustrate what would this typical basket have cost in the base year.
Determine the true importance of a risk : How can a company determine the true importance of a risk.
Growth rates-future value-present value-amortization : Assume you borrowed $12,000 at the rate of 9% and must repay it in four equal installments at the end of each of the next four years. By how much would you reduce the amount you owe in the first year?

Reviews

Write a Review

Computer Engineering Questions & Answers

  How can state the units for each metric

express the units for each metric, such as dollars per hour, rejects per day, schedule slippage per task in days, budgeted versus actual cost expenditure per task,etc. One character in a group I once had expressed the progress of laying a cable in..

  Write down a java implementation

Write down a Java implementation

  Transmition of the packet

An Ethernet MAC sub layer receives the 1510 bytes of the data from LLC layer. Explain whether the data encapsulation can be within one frame?

  List the top advantages of migrating to ipv6

List the top advantages of migrating to IPv6

  Why computers and software used to better our society

why computers and software used to better our society.

  Generate a context diagram of the system

Generate a context diagram of the system

  Develop an application with the chosen dbms

A school intends to procure the integrated student management application holding all details of registered students including personal information, courses taken, and examination grades.

  Does case or object-oriented design techniques used

consider the alternatives that were considered during the design stage of the project. What were the considerations in choosing the best alternative strategy.

  Classify and discuss compensation potentially

Classify and discuss compensation potentially.

  Exploring web for security education

Explore the Web for security education and the training programs within your area. Keep down a list and examine which of the category has most examples.

  How standards are intended to create unity

standard issued by either the International Telecommunication Union.It was also stated that "Although standards are intended to create unity, they can have the opposite effect".

  Identify the security provisions

Identify the security provisions

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