Modify class Date of Fig. 8.7 to perform error checking on the initializer values for variables month,
Question:
Modify class Date of Fig. 8.7 to perform error checking on the initializer values for variables month, day and year (currently it validates only the month and day). Provide a method nextDay to increment the day by one. Write a program that tests method nextDay in a loop that prints the date during each iteration to illustrate that the method works correctly. Test the following cases:
a) Incrementing into the next month and
b) Incrementing into the next year.
Fig. 8.7
Transcribed Image Text:
I // Fig. 8.7: Date.java // Date class declaration. 2 3 4 5 6 7 8 9 10 II 12 13 14 15 16 17 18 19 20 21 22 23 24 25 N N N N N M M M M 26 27 28 29 30 31 32 33 34 35 36 37 38 public class Date { 39 40 41 42 43 44 45 } private int month; // 1-12 private int day; // 1-31 based on month private int year; // any year private static final int[] daysPerMonth = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; // constructor: confirm proper value for month and day given the year public Date(int month, int day, int year) { // check if month in range if (month 12) { throw new Illegal ArgumentException ( "month (" + month + ") must be 1-12"); } } // check if day in range for month if (day < 0 || (day> daysPerMonth [month] && ! (month == 2 && day throw new Illegal ArgumentException ("day (" + day + ") out-of-range for the specified month and year"); == == } // check for leap year if month is 2 and day is 29 if (month= 2 && day 29 && ! (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0))) { throw new Illegal ArgumentException ("day (" + day + ") out-of-range for the specified month and year"); } // return a String of the form month/day/year public String toString() { return String.format("%d/%d/%d", month, day, year); 29))) { } this month = month; this.day = day; this.year = year; System.out.printf("Date object constructor for date %s %n", this);
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 33% (3 reviews)
To update the Date class to perform error checking on the year as well as to provide a nextDay ...View the full answer
Answered By
Bhartendu Goyal
Professional, Experienced, and Expert tutor who will provide speedy and to-the-point solutions. I have been teaching students for 5 years now in different subjects and it's truly been one of the most rewarding experiences of my life. I have also done one-to-one tutoring with 100+ students and help them achieve great subject knowledge. I have expertise in computer subjects like C++, C, Java, and Python programming and other computer Science related fields. Many of my student's parents message me that your lessons improved their children's grades and this is the best only thing you want as a tea...
3.00+
2+ Reviews
10+ Question Solved
Related Book For
Java How To Program Late Objects Version
ISBN: 9780136123712
8th Edition
Authors: Paul Deitel, Deitel & Associates
Question Posted:
Students also viewed these Computer science questions
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
A client calls in to sell their entire long position (300 shares) of AAPL and wanted you to walk them through the process. While going through BPROS you notice they are also short 3 calls contracts...
-
Case Study: Quick Fix Dental Practice Technology requirements Application must be built using Visual Studio 2019 or Visual Studio 2017, professional or enterprise. The community edition is not...
-
Alton division (A) and Birmingham division (B) are two manufacturing divisions of Conglom plc. Both of these divisions make a single standardized product; A makes product I and B makes product J....
-
Using the results of linearized theory calculate the lift and wave-drag coefficients for an infinitely thin flat plate in a Mach 2.6 free stream at angles of attack of (a) a = 5 (b) a = 15 (c) a = 30...
-
When should the change in accounting for a long-term investment from the cost method to the equity method be accounted for retroactively, and when should it be accounted for prospectively?
-
Explain the logic of the residual dividend model, the steps a firm would take to implement it, and the reason it is more likely to be used to establish a long-run payout target than to set the actual...
-
Warner Co. entered into the following transactions involving short-term liabilities in 2016 and 2017. 2016 Apr. 22 Purchased $5,000 of merchandise on credit from Fox-Pro, terms n30. Warner uses the...
-
Scatter Diagrams and High-Low Cost Estimation Assume the local Pearle Vision has the following information on the number of sales orders received and order-processing costs. Scatter Diagrams and...
-
Write code that generates n random numbers in the range 10100.
-
Modify class Time2 of Fig. 8.5 to include a tick method that increments the time stored in a Time2 object by one second. Provide method incrementMinute to increment the minute by one and method...
-
Interview three or four adults about credit. Ask them the following questions: (a) How do you feel about the use of credit? (b) Do you think interest rates charged on credit cards and accounts are...
-
Jason is a sole trader in the architecture industry. For the year ending 30 June 2019, Jason hired a 3D model designer, Sarah, to help him with the growing business. At the end of the year he has the...
-
Read Case 14-1 Trojan Technologies (15th ed., p. 426 OR 16th ed., p. 431) Guiding Questions and additional information: In preparing your case study, ensure that you answer the following questions:...
-
Jorge Rimert works for Road to Success Collection Agency. He oversees mailing out collection notices to patients. Upon review of the patients who have not paid from Hideaway Hospital, Jorge notices...
-
An epidemiologist plans to conduct a survey to estimate the percentage of women who give birth. How many women must be surveyed in order to be 99% confident that the estimated percentage is in error...
-
A 100 acre plot of land has a concentration time of 80 minutes. The area is residential single family homes with a C-0.40. What is the percent Increase in stormwater runoff from a 50 year recurrence...
-
Suppose that for some function g, g(x + 3) = 2x + 1. Find g(-1).
-
A handrail, which weighs 120 N and is 1.8 m long. was mounted to a wall adjacent to a small set of steps (Figure P4.26). The support at A has broken, and the rail has fallen about the loose bolt at 8...
-
Why are different inter-AS and intra-AS protocols used in the Internet?
-
Is it necessary that every autonomous system use the same intra-AS routing algorithm? Why or why not?
-
What is the count to infinity problem in distance vector routing?
-
Palisade Creek Co. is a merchandising business that uses the perpetual inventory system. The account balances for Palisade Creek Co. as of May 1, 2019 (unless otherwise indicated), are as follows:...
-
1-When accounting for an acquisition, goodwill is the difference between what two things? 2- What factors should be considered when deciding whether an acquisition should be financed with cash or...
-
What is the main friction Fluidity aims to address? REAL STATE
Study smarter with the SolutionInn App