Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Computer Engineering Expert

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

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M9205421

Have any Question?


Related Questions in Computer Engineering

Every day your friend commutes to school on the subway at 9

Every day your friend commutes to school on the subway at 9 AM. If the subway is on time, she will stop for a $3 coffee on the way to class. If the subway is delayed she skips the coffee and goes straight to class. The p ...

What is the prupose of adding nahco3 solution to dissolve

What is the prupose of adding NaHCO3 solution to dissolve the crude products in refinning process (Chemistry)

Can someone help me identify how intrustion detection

Can someone help me identify how Intrustion detection system and intrusion prevent system can help protect confidentiality, integrity and availability

A standard 52 card playing deck assigns a unique

A standard 52 card playing deck assigns a unique combination of 13 ranks (2,3,4,5,6,7,8,9,10,J,Q,K,A) and 4 suits (Clubs, Diamonds, Hearts, Spades) to each card (13  4 = 52). Suppose 5 cards are selected at random. Deriv ...

Discuss how today the internet has brought millions of

Discuss how today, the internet has brought millions of unsecured computer networks into communication with each other.

Jeff decides to start saving some money from this upcoming

Jeff decides to start saving some money from this upcoming month onwards. He decides to save only $500 at first, but each month he will increase the amount invested by $100. He will do it for 60 months (including the fir ...

Albert hoffmans wife has an ipod shuffle with five songs in

Albert Hoffman's wife has an iPod shuffle with five songs in her library: November Rain  by Guns 'N Roses Ain't No Mountain High Enough  by Nicholas Ashford and Valerie Simpson Call Me Maybe  by Carly Rae Jepsen Rainbow ...

Solve the water-jug puzzle given a 3-litter jug named three

Solve the water-jug puzzle given a 3-litter jug, named Three, and a 4-liter jug, named Four. Initially, Three and Four are empty. Either jug can be filled with water from a tap T, and one can discard water from either ju ...

Question 1 suppose i need 10 bits to specify the offset

Question 1 : Suppose I need 10 bits to specify the offset within a page and 22 bits to specify the virtual page number and 18 bits to specify the physical page number. How big is a page in bytes? How big is the virtual m ...

A software has x bugs a team finds 19 bugs in it another

A software has x bugs. A team finds 19 bugs in it. Another team finds 11 bugs in it. Of these, 3 bugs were common to both teams. What is the value of x, assuming that the all the bugs (found and remaining) have the same ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As