This programming assignment involves writing a Java application that inputs a date from the user, and...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
This programming assignment involves writing a Java application that inputs a date from the user, and calculates how many days have elapsed from January 1 (of that same year) to the date specified. The user enters the date from the console, as a string of characters in the format: MM DD YYYY. For example, if the user enters 03 01 2012 then this represents March 1, 2012. In this case, the number of days elapsed is 61: 31 for January, 29 for February (2012 is a "leap year"), and 1 during March itself Similarly, if the input were 01 01 2010 then the output should indicate that I day has elapsed. IMPORTANT: Do not use any standard calendar-related classes from the Java library for this project. The central idea of this assignment is to implement and use our own date methods. If we were to use a library class such as "Calendar", "GregorianCalendar", or "Date", that would be cheating. In addition to returning the correct result, your program must check for and deal with the following issues: 1. Non-numeric data: You may use standard Java library classes to check if the input is or is not valid numeric data. An appropriate error message for this case would be "Non-numeric data entered: mm dd yyyy". 2. Leap years: Not all years that are evenly divisible by four are leap years. Years that end in "00" (so- called centurial years) are leap years only if they are also divisible by four hundred. 3. Inappropriate month entered: Allowable values are 01-12. (There is no month 13, or month 0.) The error message might be: "Invalid month: 4. Inappropriate day entered: The day value must be between 01 and the maximum for that particular month and year. For example: January and March always have 31 days; February has either 28 or 29, depending on the year. The error message might be: "Invalid day: dd, for month-mm, year-yyyy". 5. Inappropriate year: for our purposes, we will allow year values in the range of 1900-2100. After one date string is processed, either successfully or with an error message, the program should ask the user to enter another date string. This "main loop" continues until the user enters the "q" command. Sample Output Test your program with different date values, both valid and invalid. The sample output that follows shows correct results for several test cases. Your error messages should be appropriate for whatever error your program detects, but your error messages do not need to be identical to the examples shown. (In these examples, the text that the user types is shown in BOLD font. The actual input/output will all be displayed in the same font.) Sample Console Input/Output This program accepts numeric dates in the format MM DD YYYY. Please enter numeric date (or q to exit program): 01 01 2016 1 day has elapsed from Jan 01, 2016 to Jan 01, 2016. Please enter numeric date (or q to exit program): 01 02 2020 2 days have elapsed from Jan 01, 2020 to Jan 02, 2020. Please enter numeric date (or q to exit program): 02 01 1999 32 days have elapsed from Jan 01, 1999 to Feb 01, 1999. Please enter numeric date (or q to exit program): 02 28 2003 59 days have elapsed from Jan 01, 2003 to Feb 28, 2003. Please enter numeric date (or q to exit program): 02 29 2004 60 days have elapsed from Jan 01, 2004 to Feb 29, 2004. Please enter numeric date (or q to exit program) : 03 01 2005 60 days have elapsed from Jan 01, 2005 to Mar 01, 2005. Please enter numeric date (or q to exit program): 03 01 2000 61 days have elapsed from Jan 01, 2000 to Mar 01, 2000. Please enter numeric date (or q to exit program): 04 01 2006 91 days have elapsed from Jan 01, 2006 to Apr 01, 2006. Please enter numeric date (or q to exit program): 04 01 2008 92 days have elapsed from Jan 01, 2008 to Apr 01, 2008. Please enter numeric date (or q to exit program): 04 01 1900 91 days have elapsed from Jan 01, 1900 to Apr 01, 1900. Please enter numeric date (or q to exit program): 04 30 2011 120 days have elapsed from Jan 01, 2011 to Apr 30, 2011. Please enter numeric date (or q to exit program): 04 30 2012 121 days have elapsed from Jan 01, 2012 to Apr 30, 2012. Please enter numeric date (or q to exit program): 12 31 2000 366 days have elapsed from Jan 01, 2000 to Dec 31, 2000. Please enter numeric date (or q to exit program): 12 31 2001 365 days have elapsed from Jan 01, 2001 to Dec 31, 2001. Please enter numeric date (or q to exit program): a 02 1999 Non-numeric data entered: a 02 1999 Please enter numeric date (or q to exit program): 0 22 2020 ERROR: Invalid numeric month: 0 ERROR: Invalid Date string "0 22 2020" resulted in invalid numeric date: month=00, day=22, year=2020 Please enter numeric date (or q to exit program): 13 11 2001 ERROR: Invalid numeric month: 13 ERROR: Invalid Date string "13 11 2001" resulted in invalid numeric date: month=13, day=11, year=2001 Sample Console Input/Output Please enter numeric date (or q to exit program): 01 32 2003 ERROR: Invalid day 32, for numeric month: 1 (year = 2003) ERROR: Invalid Date string "01 32 2003" resulted in invalid numeric date: month=01, day=32, year=2003 Please enter numeric date (or q to exit program): 02 29 2003 ERROR: Invalid day 29, for numeric month: 2 (year 2003) ERROR: Invalid Date string "02 29 2003" resulted in invalid numeric date: month=02, day-29, year=2003 Please enter numeric date (or q to exit program): 02 29 2004 60 days have elapsed from Jan 01, 2004 to Feb 29, 2004. Please enter numeric date (or q to exit program): 02 30 2004 ERROR: Invalid day 30, for numeric month: 2 (year = 2004) ERROR: Invalid Date string "02 30 2004" resulted in invalid numeric date: month=02, day-30, year=2004 Please enter numeric date (or q to exit program): 04 31 2005 ERROR: Invalid day 31, for numeric month: 4 (year = 2005) ERROR: Invalid Date string "04 31 2005" resulted in invalid numeric date: month=04, day-31, year=2005 Please enter numeric date (or q to exit program): 06 31 2008 ERROR: Invalid day 31, for numeric month: 6 (year = 2008) ERROR: Invalid Date string "06 31 2008" resulted in invalid numeric date: month=06, day=31, year=2008 Please enter numeric date (or q to exit program): 09 31 2012 ERROR: Invalid day 31, for numeric month: 9 (year 2012) ERROR: Invalid Date string "09 31 2012" resulted in invalid numeric date: month=09, day=31, year=2012 Please enter numeric date (or q to exit program) : 09 35 2012 ERROR: Invalid day 35, for numeric month: 9 (year = 2012) ERROR: Invalid Date string "09 35 2012" resulted in invalid numeric date: month=09, day=35, year-2012 Please enter numeric date (or q to exit program): 11 31 1969 ERROR: Invalid day 31, for numeric month: 11 (year = 1969) ERROR: Invalid Date string "11 31 1969" resulted in invalid numeric date: month=11, day-31, year=1969 Please enter numeric date (or q to exit program) : 01 01 2100 1 day has elapsed from Jan 01, 2100 to Jan 01, 2100. Please enter numeric date (or q to exit program): 01 01 2101 ERROR: Invalid year 2101. Year must be between 1900 and 2100. ERROR: Invalid Date string "01 01 2101" resulted in invalid numeric date: month=01, day=01, year=2101 Please enter numeric date (or q to exit program): 12 31 1900 365 days have elapsed from Jan 01, 1900 to Dec 31, 1900. Please enter numeric date (or q to exit program): 12 31 1899 ERROR: Invalid year 1899. Year must be between 1900 and 2100. ERROR: Invalid Date string "12 31 1899" resulted in invalid numeric date: month=12, day-31, year=1899 Please enter numeric date (or q to exit program): q Exit program. This programming assignment involves writing a Java application that inputs a date from the user, and calculates how many days have elapsed from January 1 (of that same year) to the date specified. The user enters the date from the console, as a string of characters in the format: MM DD YYYY. For example, if the user enters 03 01 2012 then this represents March 1, 2012. In this case, the number of days elapsed is 61: 31 for January, 29 for February (2012 is a "leap year"), and 1 during March itself Similarly, if the input were 01 01 2010 then the output should indicate that I day has elapsed. IMPORTANT: Do not use any standard calendar-related classes from the Java library for this project. The central idea of this assignment is to implement and use our own date methods. If we were to use a library class such as "Calendar", "GregorianCalendar", or "Date", that would be cheating. In addition to returning the correct result, your program must check for and deal with the following issues: 1. Non-numeric data: You may use standard Java library classes to check if the input is or is not valid numeric data. An appropriate error message for this case would be "Non-numeric data entered: mm dd yyyy". 2. Leap years: Not all years that are evenly divisible by four are leap years. Years that end in "00" (so- called centurial years) are leap years only if they are also divisible by four hundred. 3. Inappropriate month entered: Allowable values are 01-12. (There is no month 13, or month 0.) The error message might be: "Invalid month: 4. Inappropriate day entered: The day value must be between 01 and the maximum for that particular month and year. For example: January and March always have 31 days; February has either 28 or 29, depending on the year. The error message might be: "Invalid day: dd, for month-mm, year-yyyy". 5. Inappropriate year: for our purposes, we will allow year values in the range of 1900-2100. After one date string is processed, either successfully or with an error message, the program should ask the user to enter another date string. This "main loop" continues until the user enters the "q" command. Sample Output Test your program with different date values, both valid and invalid. The sample output that follows shows correct results for several test cases. Your error messages should be appropriate for whatever error your program detects, but your error messages do not need to be identical to the examples shown. (In these examples, the text that the user types is shown in BOLD font. The actual input/output will all be displayed in the same font.) Sample Console Input/Output This program accepts numeric dates in the format MM DD YYYY. Please enter numeric date (or q to exit program): 01 01 2016 1 day has elapsed from Jan 01, 2016 to Jan 01, 2016. Please enter numeric date (or q to exit program): 01 02 2020 2 days have elapsed from Jan 01, 2020 to Jan 02, 2020. Please enter numeric date (or q to exit program): 02 01 1999 32 days have elapsed from Jan 01, 1999 to Feb 01, 1999. Please enter numeric date (or q to exit program): 02 28 2003 59 days have elapsed from Jan 01, 2003 to Feb 28, 2003. Please enter numeric date (or q to exit program): 02 29 2004 60 days have elapsed from Jan 01, 2004 to Feb 29, 2004. Please enter numeric date (or q to exit program) : 03 01 2005 60 days have elapsed from Jan 01, 2005 to Mar 01, 2005. Please enter numeric date (or q to exit program): 03 01 2000 61 days have elapsed from Jan 01, 2000 to Mar 01, 2000. Please enter numeric date (or q to exit program): 04 01 2006 91 days have elapsed from Jan 01, 2006 to Apr 01, 2006. Please enter numeric date (or q to exit program): 04 01 2008 92 days have elapsed from Jan 01, 2008 to Apr 01, 2008. Please enter numeric date (or q to exit program): 04 01 1900 91 days have elapsed from Jan 01, 1900 to Apr 01, 1900. Please enter numeric date (or q to exit program): 04 30 2011 120 days have elapsed from Jan 01, 2011 to Apr 30, 2011. Please enter numeric date (or q to exit program): 04 30 2012 121 days have elapsed from Jan 01, 2012 to Apr 30, 2012. Please enter numeric date (or q to exit program): 12 31 2000 366 days have elapsed from Jan 01, 2000 to Dec 31, 2000. Please enter numeric date (or q to exit program): 12 31 2001 365 days have elapsed from Jan 01, 2001 to Dec 31, 2001. Please enter numeric date (or q to exit program): a 02 1999 Non-numeric data entered: a 02 1999 Please enter numeric date (or q to exit program): 0 22 2020 ERROR: Invalid numeric month: 0 ERROR: Invalid Date string "0 22 2020" resulted in invalid numeric date: month=00, day=22, year=2020 Please enter numeric date (or q to exit program): 13 11 2001 ERROR: Invalid numeric month: 13 ERROR: Invalid Date string "13 11 2001" resulted in invalid numeric date: month=13, day=11, year=2001 Sample Console Input/Output Please enter numeric date (or q to exit program): 01 32 2003 ERROR: Invalid day 32, for numeric month: 1 (year = 2003) ERROR: Invalid Date string "01 32 2003" resulted in invalid numeric date: month=01, day=32, year=2003 Please enter numeric date (or q to exit program): 02 29 2003 ERROR: Invalid day 29, for numeric month: 2 (year 2003) ERROR: Invalid Date string "02 29 2003" resulted in invalid numeric date: month=02, day-29, year=2003 Please enter numeric date (or q to exit program): 02 29 2004 60 days have elapsed from Jan 01, 2004 to Feb 29, 2004. Please enter numeric date (or q to exit program): 02 30 2004 ERROR: Invalid day 30, for numeric month: 2 (year = 2004) ERROR: Invalid Date string "02 30 2004" resulted in invalid numeric date: month=02, day-30, year=2004 Please enter numeric date (or q to exit program): 04 31 2005 ERROR: Invalid day 31, for numeric month: 4 (year = 2005) ERROR: Invalid Date string "04 31 2005" resulted in invalid numeric date: month=04, day-31, year=2005 Please enter numeric date (or q to exit program): 06 31 2008 ERROR: Invalid day 31, for numeric month: 6 (year = 2008) ERROR: Invalid Date string "06 31 2008" resulted in invalid numeric date: month=06, day=31, year=2008 Please enter numeric date (or q to exit program): 09 31 2012 ERROR: Invalid day 31, for numeric month: 9 (year 2012) ERROR: Invalid Date string "09 31 2012" resulted in invalid numeric date: month=09, day=31, year=2012 Please enter numeric date (or q to exit program) : 09 35 2012 ERROR: Invalid day 35, for numeric month: 9 (year = 2012) ERROR: Invalid Date string "09 35 2012" resulted in invalid numeric date: month=09, day=35, year-2012 Please enter numeric date (or q to exit program): 11 31 1969 ERROR: Invalid day 31, for numeric month: 11 (year = 1969) ERROR: Invalid Date string "11 31 1969" resulted in invalid numeric date: month=11, day-31, year=1969 Please enter numeric date (or q to exit program) : 01 01 2100 1 day has elapsed from Jan 01, 2100 to Jan 01, 2100. Please enter numeric date (or q to exit program): 01 01 2101 ERROR: Invalid year 2101. Year must be between 1900 and 2100. ERROR: Invalid Date string "01 01 2101" resulted in invalid numeric date: month=01, day=01, year=2101 Please enter numeric date (or q to exit program): 12 31 1900 365 days have elapsed from Jan 01, 1900 to Dec 31, 1900. Please enter numeric date (or q to exit program): 12 31 1899 ERROR: Invalid year 1899. Year must be between 1900 and 2100. ERROR: Invalid Date string "12 31 1899" resulted in invalid numeric date: month=12, day-31, year=1899 Please enter numeric date (or q to exit program): q Exit program.
Expert Answer:
Answer rating: 100% (QA)
heres a stepbystep solution to the programming assignment 1 Read the date input from the user as a s... View the full answer
Related Book For
Posted Date:
Students also viewed these programming questions
-
(6%) Problem 14: A child fills up a water gun with water from a pool. She holds the gun just completely submerged at an angle of 0 = 35 from horizontal while pulling on the handle to suck water into...
-
What is a branch delay slot and why does it arise? [7 marks] How can branch delays be avoided? If a processor exhibited one branch delay slot how would you reorder (and possibly modify) the...
-
cck3 java help them all If a processor exhibited one branch delay slot how would you reorder (and possibly modify) the instructions in the following loop to gain a performance advantage? loop ldr...
-
Let V be the volume of a can of radius r and height h, and let S be its surface area (including the top and bottom). Find r and h that minimize S subject to the constraint V = 54.
-
Explain the 'learning curve' and discuss its relevance to setting standards.
-
Suppose capital is risky and pays gross real rates of return of 1.2, 1.1, and 0.9 with probabilities .1, .7, and .2, respectively. A risk-free asset pays a safe gross real rate of return of 1.04....
-
Continuation of P10-29A: cash budgets} Refer to P10-29A. Vinning Office Supply's sales are \(70 \%\) cash and \(30 \%\) credit (use the rounded sales on the last line of \(\mathrm{P} 10-29...
-
On August 5, Synthetic Carpet Inc., a carpet wholesaler, issued for cash 500,000 shares of no-par common stock (with a stated value of $1) at $3, and on December 17, it issued for cash 5,000 shares...
-
1. Find the point of intersection of 2 + y = 5 and x - 3y = 7. 2. Use distances to determine whether or not the three points (1. 5), (-2, -1). and (4, 10) are collinear. Check your work by using...
-
Sebastian Trains Co (ST) is a UK based rail operating company which holds three UK rail franchises. The franchises allow ST to run trains on the rail network in a particular geographical area within...
-
ABC Company produces a product that requires six standard pounds per unit. The standard price is $1.30 per pound. If 500 units required 2,900 pounds, which were purchased at $1.25 per pound, what is...
-
Based on the case Thomas Green: Power, Office Politics, and a Career in Crisis. How effective was Frank Davis in his communication of negative messages or news in the case? Use specific references to...
-
Company and Industry Background 1 . What does Sleep Number Corporation do ? What industry does it compete in ? What are the core brands under the Sleep Number umbrella? 2 . What world and economic...
-
You have been given a choice between two retirement policies as described below. Policy A: You will receive equal annual payments of $10,000 beginning 35 years from now for 10 years. Policy B: You...
-
2. (a) (3 points) How many bits are there in a half byte? (b) (3 points) How many distinct patterns can you make with half a byte? 3. (8 points) Write a Python function that takes three numbers as...
-
It is required to face mill a medium cast iron block (BHN 200) to size it down from 1.1 to 1.0 thick (in a single pass of the tool) using a 5 diameter 32-toothed carbide cutting tool. The block is...
-
Harrelson Company manufactures pizza sauce through two production departments: Cooking and Canning. In each process, materials and conversion costs are incurred evenly throughout the process. For the...
-
Privitera and Freeman (2012) constructed a scale to measure or estimate the daily fat intake of participants; the scale was called the estimated daily intake scale for fat (EDIS-F). To validate the...
-
The abbreviation for the critical value of F is ____.
-
1 2 3 is / is not an accurate statement of the alternative hypothesis.
-
The null hypothesis is rejected if F is ____ the critical value of F.
-
How many Hamilton cycles are in the graph? W Complete Graph R
-
Find the number of ways to arrange the letters \(v, w, x, y\), and \(z\).
-
Find the weight of the Hamilton cycle \(m ightarrow 0 ightarrow p ightarrow n ightarrow q ightarrow m\) in the given figure. 5 5, m 3 4 n 8 5' P 5 Weighted Complete Graph with Five Vertices
Study smarter with the SolutionInn App