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)
Below is an example of a Java program that fulfills the requirements outlined in your programming assignment java import javautilScanner public class ... View the full answer
Related Book For
Posted Date:
Students also viewed these programming questions
-
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.
-
Financial statements for Askew Industries for 2018 are shown below (in thousands): _______________________________2018 Income Statement Sales................................................$ 9,000...
-
Martinez Company's ending inventory includes the following items. Product Units Cost per Unit Market per Unit $ 63 Helmets $ 59 41 Bats 34 81 113 Shoes 55 100 104 Uniforms 59 45 45 Compute the lower...
-
Employee theft is a major problem for organizations in Canada and the United States. According to one study, employee theft costs Canadian organizations more than $120 billion a year and is the cause...
-
Leisure City had sold bonds in the amount of $ 4,000,000 during the latter part of 2012 to improve its water delivery system. As a result, on December 31, 2012, its Capital Projects Fund reported...
-
The truck you have in mind is priced at $29,200. You myst pay tax and license fees of $1,900. Your credit union will make you a loan at 7.9% for 6 years. You have $3,000 to use toward the purchase....
-
The cash book (bank columns) of Ella for the month of May 207 were as follows: Ellas bank statement for May 207 showed the following: The following errors were discovered: 1. Ella had overcast the...
-
1.Consider the following notation: Let N be the number of persons to be admitted, K the set of short-listed applicants, M the set of all female applicants, R the set of all non-stanbul-region...
-
How YOUR decision making process has improved by using a decision making model Potential skill building tools that can bolster your ability to make decisions Retake the Decision Making Questionnaire...
-
In "Introduction to Disciplined Agile Delivery" why was it wrong for Dick the Database Administrator to secretly work on detailed logical and physical data models in his spare time? 1. Dick did not...
-
A 10-year bond has a par coupon of 3% and a duration of 9. A 5-year bond has a par coupon of 2% and a duration of 4.75. What is the 5 year into 5 year forward rate?Please use just the information...
-
The TD Bank Group (TD) supports several initiatives to encourage literacy and reading in Canada. TD believes that literacy is a key skill for the future. In 2000, TD established the Grade One Book...
-
The brake in the figure has a diameter of 320mm and is activated by a mechanism that exerts the same force F on each shoe. These are identical and have a face width of 39 mm. The covering is molded...
-
Earthworm contains protein which can perform the anticoagulant activity but the protein isolated from fresh samples of earthworm do not show anticoagulant activity in addition drying earthworm using...
-
What is beacon marketing? What are digital wallets?
-
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.
-
Consider the following cash flow profile and assume MARR is 10 percent/year and the finance rate is 4 percent/year. a. Determine the MIRR for this project. b. Is this project economically attractive?...
-
Consider the following cash flow profile, and assume MARR is 10 percent/year and the finance rate is 4 percent/year. a. Determine the MIRR for this project. b. Is this project economically...
-
A university pumps its water from wells located on campus. The falling water table has caused pumping costs to increase, the quantity of water available to decrease, and the quality of water to...
Study smarter with the SolutionInn App