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.
-
This puzzle is from a Russian web-site www.arbuz.uz/ and there are many solutions to it, but mine uses linear algebra and is very naive. There's a planet inhabited by arbuzoids (watermeloners, to...
-
Name three methods of sealing a closed container while allowing relative movement of some part.
-
How are interest rates and the rate of return stated?
-
Hardwood Seating Co., a manufacturer of chairs, had the following data for 2012. Sales ............ 2,400 units Sales price ......... $40 per unit Variable costs ....... $14 per unit Fixed costs...
-
Month Actual Demand Jan 740 Feb 790 Mar 920 Apr 870 May 890 Jun 910 a. Develop forecasts for July using an exponential smoothing model with =0.40. Assume the forecast for January was 760
-
You are assessing internal control in the audit of the payroll and personnel cycle for Rogers Products Company, a manufacturing company specializing in assembling computer parts. Rogers employs...
-
Why did HSBC Commercial Banking spend so much time on open innovation activities? What were the key values of open innovation to the bank, its customers and other ecosystem partners? What would be...
-
What is an audit closing conference?
-
Fabulous Fashion Ltd (FF) runs four private colleges which provide education and training for people in the fashion industry. Its two-year course includes training in design, textiles, manufacture...
-
What types of duties should be segregated, and why?
-
Which of The IIAs standards address personal presentations of audit results, written reports, and both personal presentations and written reports?
-
What are the two primary sources of follow-up documentation? Give some examples of documents from each source.
-
Graph the given function by making a table of coordinates. f(x) = 3x Complete the table of coordinates. X -2 -1 0 1 1 9 3 (Type integers or fractions. Simplify your answers.) Choose the correct graph...
-
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.
-
Why are stock markets important and what do they trade in?
-
How has the relative importance of the NYSE and LSE changed?
-
What was the importance of the Big Bang?
Study smarter with the SolutionInn App