This part of the homework requires you to submit a single java file, called Number DaysLeft...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
This part of the homework requires you to submit a single java file, called Number DaysLeft This Year.java. Make a folder called homework3 inside of the cs110Submissions folder in your computer, and you can save and edit your code as you work on this programming assignment, but it is only the file that you upload to Canvas that will be scored. Always upload only *java files. For this programming task, you'll use conditional control statements (if, if-else, if-else-if, etc.), as well as the switch statement, that you learned about in Lecture 8. Your program will prompt the user to input the day (a number), month (a string), and year (a number). You can use the Scanner class, or the JOptionPane class, to receive input from the user. Using that information, your program will calculate the number of complete days that are remaining in the year specified by the user. For full credit, your program will need to consider whether the year supplied is a leap year, which is governed by the rules in Figure 1. Samples of code were also given in class. 1. 2. 3. 4. 5. If the year is evenly divisible by 4, go to step 2. Otherwise, go to step 5. If the year is evenly divisible by 100, go to step 3. Otherwise, go to step 4. If the year is evenly divisible by 400, go to step 4. Otherwise, go to step 5. The year is a leap year (it has 366 days). The year is not a leap year (it has 365 days). Figure 1 Use a switch statement to process the month (of type String) that is input by the user, and any combination of if, if-else, if-else-if, if-else-then, etc. conditional statements, to calculate the number of days left in a year. An example of a pseudo-code for the entire program is given to you in Figure 2. // declare variables dayOfMonth and year of type int CS110, Tatiana Harrison, CWU, HW 3: Conditionals, the switch constructor Page 1 of 3 // declare variable monthName of type String // set up scanner and ask user to provide month, day of month, and year // using nextLine() for monthName, and nextInt() methods for dayOfMonth and year // declare variable days Leftin Year of type int, and assign it the value 0 // declare variable isLeap Year of type boolean, and assign it the value false // Determine whether the year is a leap year, using the following rules: // 1. If the year is evenly divisible by 4, go to step 2. Otherwise, go to step 5. // 2. If the year is evenly divisible by 100, go to step 3. Otherwise, go to step 4. // 3. If the year is evenly divisible by 400, go to step 4. Otherwise, go to step 5 // 4. The year is a leap year (it has 366 days). // 5. The year is not a leap year (it has 365 days). // Use a switch statement to determine the number of full days left in the year. // For example, December has 31 days, so daysLeftinYear = 31 - dayOfMonth. // For November, there are 30 days +31 days in December, so if user inputs November, days LeftinYear = 61 - dayOfMonth. // You will need to look up the number of days in each month. // For February, IF it is a leap year, then daysLeftinYear = 335 - dayOfMonth, and if it is NOT a // leap year, then daysLeftinYear = 334 - dayOfMonth. // For January, if it is a leap year, then daysLeftinYear = 366 - dayOfMonth. // If it is not a leap year, then if user indicates January, then daysLeftinYear = 365 - dayOfMonth. // output the correct text, (don't forget plural vs singular), to indicate how many days there are left in the year. Figure 2 The partial code for the switch statement is shown in Figure 3. switch(monthName}{ case "December": // always has 31 days daysLeftln Year = 31; daysLeftln Year -= dayOfMonth; break; case "November": // always has 30 days daysLeftinYear = 61; daysLeftinYear - dayOfMonth; break; Figure 3 To test your code, be sure to use a variety of month/day/year combinations. Using the leap year algorithm in Figure 1, the year 2000 is a leap year, but the 1900 was not. Also, the year 2007 was not a leap year, but 2008 was. Use at least these four years, to test your program for days in months that were before the leap day, and after the leap day. Sample invocations are shown in Figure 4. Sample invocation 1 (2007 is NOT a leap year): What month is it? December What day of the month is it? 30 What year is it? 2007 There is 1 complete day left in the non-leap year 2007. Sample invocation 2 (2008 is a leap year, and date input is in January): What month is it? January What day of the month is it? 31 CS110, Tatiana Harrison, CWU, HW 3: Conditionals, the switch constructor Page 2 of 3 Page < 2 of 3 ZOOM + What year is it? 2008 There are 335 complete days left in the leap year 2008. Sample invocation 3 (2009 is NOT a leap year): What month is it? January What day of the month is it? 15 What year is it? 2009 There are 350 complete days left in the non-leap year 2009. Figure 4 As you have done for homework #2, you should also submit as comments in your java file: The pseudocode of your program A description of two ways that your program crashes when it is run. RUBRIC Item Code compiles and correct logic Program compiles w/o errors Switch statement is correct If statements for leap year logic calculation is correct calculation is correct Use of boolean variables is correct Program outputs proper messages (leap / non-leap year plural vs singular number of days so far) Output is correct Year 2007: non-leap year Year 2008: leap year Year 2009: non-leap year Leap/non-leap year day counts are correct Code commented / indented • Name included • Date included • Short description included Good variable names Inputs that break code (A description of two ways that your program crashes when it is run) Pseudocode Total CS110, Tatiana Harrison, CWU, HW 3: Conditionals, the switch constructor Points Available 20 10 10 10 10 20 5 5 5 5 100 Page 3 of 3 Page < 3 of 3 ZOOM + This part of the homework requires you to submit a single java file, called Number DaysLeft This Year.java. Make a folder called homework3 inside of the cs110Submissions folder in your computer, and you can save and edit your code as you work on this programming assignment, but it is only the file that you upload to Canvas that will be scored. Always upload only *java files. For this programming task, you'll use conditional control statements (if, if-else, if-else-if, etc.), as well as the switch statement, that you learned about in Lecture 8. Your program will prompt the user to input the day (a number), month (a string), and year (a number). You can use the Scanner class, or the JOptionPane class, to receive input from the user. Using that information, your program will calculate the number of complete days that are remaining in the year specified by the user. For full credit, your program will need to consider whether the year supplied is a leap year, which is governed by the rules in Figure 1. Samples of code were also given in class. 1. 2. 3. 4. 5. If the year is evenly divisible by 4, go to step 2. Otherwise, go to step 5. If the year is evenly divisible by 100, go to step 3. Otherwise, go to step 4. If the year is evenly divisible by 400, go to step 4. Otherwise, go to step 5. The year is a leap year (it has 366 days). The year is not a leap year (it has 365 days). Figure 1 Use a switch statement to process the month (of type String) that is input by the user, and any combination of if, if-else, if-else-if, if-else-then, etc. conditional statements, to calculate the number of days left in a year. An example of a pseudo-code for the entire program is given to you in Figure 2. // declare variables dayOfMonth and year of type int CS110, Tatiana Harrison, CWU, HW 3: Conditionals, the switch constructor Page 1 of 3 This part of the homework requires you to submit a single java file, called Number DaysLeft This Year.java. Make a folder called homework3 inside of the cs110Submissions folder in your computer, and you can save and edit your code as you work on this programming assignment, but it is only the file that you upload to Canvas that will be scored. Always upload only *java files. For this programming task, you'll use conditional control statements (if, if-else, if-else-if, etc.), as well as the switch statement, that you learned about in Lecture 8. Your program will prompt the user to input the day (a number), month (a string), and year (a number). You can use the Scanner class, or the JOptionPane class, to receive input from the user. Using that information, your program will calculate the number of complete days that are remaining in the year specified by the user. For full credit, your program will need to consider whether the year supplied is a leap year, which is governed by the rules in Figure 1. Samples of code were also given in class. 1. 2. 3. 4. 5. If the year is evenly divisible by 4, go to step 2. Otherwise, go to step 5. If the year is evenly divisible by 100, go to step 3. Otherwise, go to step 4. If the year is evenly divisible by 400, go to step 4. Otherwise, go to step 5. The year is a leap year (it has 366 days). The year is not a leap year (it has 365 days). Figure 1 Use a switch statement to process the month (of type String) that is input by the user, and any combination of if, if-else, if-else-if, if-else-then, etc. conditional statements, to calculate the number of days left in a year. An example of a pseudo-code for the entire program is given to you in Figure 2. // declare variables dayOfMonth and year of type int CS110, Tatiana Harrison, CWU, HW 3: Conditionals, the switch constructor Page 1 of 3 This part of the homework requires you to submit a single java file, called Number DaysLeft This Year.java. Make a folder called homework3 inside of the cs110Submissions folder in your computer, and you can save and edit your code as you work on this programming assignment, but it is only the file that you upload to Canvas that will be scored. Always upload only *java files. For this programming task, you'll use conditional control statements (if, if-else, if-else-if, etc.), as well as the switch statement, that you learned about in Lecture 8. Your program will prompt the user to input the day (a number), month (a string), and year (a number). You can use the Scanner class, or the JOptionPane class, to receive input from the user. Using that information, your program will calculate the number of complete days that are remaining in the year specified by the user. For full credit, your program will need to consider whether the year supplied is a leap year, which is governed by the rules in Figure 1. Samples of code were also given in class. 1. 2. 3. 4. 5. If the year is evenly divisible by 4, go to step 2. Otherwise, go to step 5. If the year is evenly divisible by 100, go to step 3. Otherwise, go to step 4. If the year is evenly divisible by 400, go to step 4. Otherwise, go to step 5. The year is a leap year (it has 366 days). The year is not a leap year (it has 365 days). Figure 1 Use a switch statement to process the month (of type String) that is input by the user, and any combination of if, if-else, if-else-if, if-else-then, etc. conditional statements, to calculate the number of days left in a year. An example of a pseudo-code for the entire program is given to you in Figure 2. // declare variables dayOfMonth and year of type int CS110, Tatiana Harrison, CWU, HW 3: Conditionals, the switch constructor Page 1 of 3 // declare variable monthName of type String // set up scanner and ask user to provide month, day of month, and year // using nextLine() for monthName, and nextInt() methods for dayOfMonth and year // declare variable days Leftin Year of type int, and assign it the value 0 // declare variable isLeap Year of type boolean, and assign it the value false // Determine whether the year is a leap year, using the following rules: // 1. If the year is evenly divisible by 4, go to step 2. Otherwise, go to step 5. // 2. If the year is evenly divisible by 100, go to step 3. Otherwise, go to step 4. // 3. If the year is evenly divisible by 400, go to step 4. Otherwise, go to step 5 // 4. The year is a leap year (it has 366 days). // 5. The year is not a leap year (it has 365 days). // Use a switch statement to determine the number of full days left in the year. // For example, December has 31 days, so daysLeftinYear = 31 - dayOfMonth. // For November, there are 30 days +31 days in December, so if user inputs November, days LeftinYear = 61 - dayOfMonth. // You will need to look up the number of days in each month. // For February, IF it is a leap year, then daysLeftinYear = 335 - dayOfMonth, and if it is NOT a // leap year, then daysLeftinYear = 334 - dayOfMonth. // For January, if it is a leap year, then daysLeftinYear = 366 - dayOfMonth. // If it is not a leap year, then if user indicates January, then daysLeftinYear = 365 - dayOfMonth. // output the correct text, (don't forget plural vs singular), to indicate how many days there are left in the year. Figure 2 The partial code for the switch statement is shown in Figure 3. switch(monthName}{ case "December": // always has 31 days daysLeftln Year = 31; daysLeftln Year -= dayOfMonth; break; case "November": // always has 30 days daysLeftinYear = 61; daysLeftinYear - dayOfMonth; break; Figure 3 To test your code, be sure to use a variety of month/day/year combinations. Using the leap year algorithm in Figure 1, the year 2000 is a leap year, but the 1900 was not. Also, the year 2007 was not a leap year, but 2008 was. Use at least these four years, to test your program for days in months that were before the leap day, and after the leap day. Sample invocations are shown in Figure 4. Sample invocation 1 (2007 is NOT a leap year): What month is it? December What day of the month is it? 30 What year is it? 2007 There is 1 complete day left in the non-leap year 2007. Sample invocation 2 (2008 is a leap year, and date input is in January): What month is it? January What day of the month is it? 31 CS110, Tatiana Harrison, CWU, HW 3: Conditionals, the switch constructor Page 2 of 3 Page < 2 of 3 ZOOM + // declare variable monthName of type String // set up scanner and ask user to provide month, day of month, and year // using nextLine() for monthName, and nextInt() methods for dayOfMonth and year // declare variable days Leftin Year of type int, and assign it the value 0 // declare variable isLeap Year of type boolean, and assign it the value false // Determine whether the year is a leap year, using the following rules: // 1. If the year is evenly divisible by 4, go to step 2. Otherwise, go to step 5. // 2. If the year is evenly divisible by 100, go to step 3. Otherwise, go to step 4. // 3. If the year is evenly divisible by 400, go to step 4. Otherwise, go to step 5 // 4. The year is a leap year (it has 366 days). // 5. The year is not a leap year (it has 365 days). // Use a switch statement to determine the number of full days left in the year. // For example, December has 31 days, so daysLeftinYear = 31 - dayOfMonth. // For November, there are 30 days +31 days in December, so if user inputs November, days LeftinYear = 61 - dayOfMonth. // You will need to look up the number of days in each month. // For February, IF it is a leap year, then daysLeftinYear = 335 - dayOfMonth, and if it is NOT a // leap year, then daysLeftinYear = 334 - dayOfMonth. // For January, if it is a leap year, then daysLeftinYear = 366 - dayOfMonth. // If it is not a leap year, then if user indicates January, then daysLeftinYear = 365 - dayOfMonth. // output the correct text, (don't forget plural vs singular), to indicate how many days there are left in the year. Figure 2 The partial code for the switch statement is shown in Figure 3. switch(monthName}{ case "December": // always has 31 days daysLeftln Year = 31; daysLeftln Year -= dayOfMonth; break; case "November": // always has 30 days daysLeftinYear = 61; daysLeftinYear - dayOfMonth; break; Figure 3 To test your code, be sure to use a variety of month/day/year combinations. Using the leap year algorithm in Figure 1, the year 2000 is a leap year, but the 1900 was not. Also, the year 2007 was not a leap year, but 2008 was. Use at least these four years, to test your program for days in months that were before the leap day, and after the leap day. Sample invocations are shown in Figure 4. Sample invocation 1 (2007 is NOT a leap year): What month is it? December What day of the month is it? 30 What year is it? 2007 There is 1 complete day left in the non-leap year 2007. Sample invocation 2 (2008 is a leap year, and date input is in January): What month is it? January What day of the month is it? 31 CS110, Tatiana Harrison, CWU, HW 3: Conditionals, the switch constructor Page 2 of 3 Page < 2 of 3 ZOOM + // declare variable monthName of type String // set up scanner and ask user to provide month, day of month, and year // using nextLine() for monthName, and nextInt() methods for dayOfMonth and year // declare variable days Leftin Year of type int, and assign it the value 0 // declare variable isLeap Year of type boolean, and assign it the value false // Determine whether the year is a leap year, using the following rules: // 1. If the year is evenly divisible by 4, go to step 2. Otherwise, go to step 5. // 2. If the year is evenly divisible by 100, go to step 3. Otherwise, go to step 4. // 3. If the year is evenly divisible by 400, go to step 4. Otherwise, go to step 5 // 4. The year is a leap year (it has 366 days). // 5. The year is not a leap year (it has 365 days). // Use a switch statement to determine the number of full days left in the year. // For example, December has 31 days, so daysLeftinYear = 31 - dayOfMonth. // For November, there are 30 days +31 days in December, so if user inputs November, days LeftinYear = 61 - dayOfMonth. // You will need to look up the number of days in each month. // For February, IF it is a leap year, then daysLeftinYear = 335 - dayOfMonth, and if it is NOT a // leap year, then daysLeftinYear = 334 - dayOfMonth. // For January, if it is a leap year, then daysLeftinYear = 366 - dayOfMonth. // If it is not a leap year, then if user indicates January, then daysLeftinYear = 365 - dayOfMonth. // output the correct text, (don't forget plural vs singular), to indicate how many days there are left in the year. Figure 2 The partial code for the switch statement is shown in Figure 3. switch(monthName}{ case "December": // always has 31 days daysLeftln Year = 31; daysLeftln Year -= dayOfMonth; break; case "November": // always has 30 days daysLeftinYear = 61; daysLeftinYear - dayOfMonth; break; Figure 3 To test your code, be sure to use a variety of month/day/year combinations. Using the leap year algorithm in Figure 1, the year 2000 is a leap year, but the 1900 was not. Also, the year 2007 was not a leap year, but 2008 was. Use at least these four years, to test your program for days in months that were before the leap day, and after the leap day. Sample invocations are shown in Figure 4. Sample invocation 1 (2007 is NOT a leap year): What month is it? December What day of the month is it? 30 What year is it? 2007 There is 1 complete day left in the non-leap year 2007. Sample invocation 2 (2008 is a leap year, and date input is in January): What month is it? January What day of the month is it? 31 CS110, Tatiana Harrison, CWU, HW 3: Conditionals, the switch constructor Page 2 of 3 Page < 2 of 3 ZOOM + What year is it? 2008 There are 335 complete days left in the leap year 2008. Sample invocation 3 (2009 is NOT a leap year): What month is it? January What day of the month is it? 15 What year is it? 2009 There are 350 complete days left in the non-leap year 2009. Figure 4 As you have done for homework #2, you should also submit as comments in your java file: The pseudocode of your program A description of two ways that your program crashes when it is run. RUBRIC Item Code compiles and correct logic Program compiles w/o errors Switch statement is correct If statements for leap year logic calculation is correct calculation is correct Use of boolean variables is correct Program outputs proper messages (leap / non-leap year plural vs singular number of days so far) Output is correct Year 2007: non-leap year Year 2008: leap year Year 2009: non-leap year Leap/non-leap year day counts are correct Code commented / indented • Name included • Date included • Short description included Good variable names Inputs that break code (A description of two ways that your program crashes when it is run) Pseudocode Total CS110, Tatiana Harrison, CWU, HW 3: Conditionals, the switch constructor Points Available 20 10 10 10 10 20 5 5 5 5 100 Page 3 of 3 Page < 3 of 3 ZOOM + What year is it? 2008 There are 335 complete days left in the leap year 2008. Sample invocation 3 (2009 is NOT a leap year): What month is it? January What day of the month is it? 15 What year is it? 2009 There are 350 complete days left in the non-leap year 2009. Figure 4 As you have done for homework #2, you should also submit as comments in your java file: The pseudocode of your program A description of two ways that your program crashes when it is run. RUBRIC Item Code compiles and correct logic Program compiles w/o errors Switch statement is correct If statements for leap year logic calculation is correct calculation is correct Use of boolean variables is correct Program outputs proper messages (leap / non-leap year plural vs singular number of days so far) Output is correct Year 2007: non-leap year Year 2008: leap year Year 2009: non-leap year Leap/non-leap year day counts are correct Code commented / indented • Name included • Date included • Short description included Good variable names Inputs that break code (A description of two ways that your program crashes when it is run) Pseudocode Total CS110, Tatiana Harrison, CWU, HW 3: Conditionals, the switch constructor Points Available 20 10 10 10 10 20 5 5 5 5 100 Page 3 of 3 Page < 3 of 3 ZOOM + What year is it? 2008 There are 335 complete days left in the leap year 2008. Sample invocation 3 (2009 is NOT a leap year): What month is it? January What day of the month is it? 15 What year is it? 2009 There are 350 complete days left in the non-leap year 2009. Figure 4 As you have done for homework #2, you should also submit as comments in your java file: The pseudocode of your program A description of two ways that your program crashes when it is run. RUBRIC Item Code compiles and correct logic Program compiles w/o errors Switch statement is correct If statements for leap year logic calculation is correct calculation is correct Use of boolean variables is correct Program outputs proper messages (leap / non-leap year plural vs singular number of days so far) Output is correct Year 2007: non-leap year Year 2008: leap year Year 2009: non-leap year Leap/non-leap year day counts are correct Code commented / indented • Name included • Date included • Short description included Good variable names Inputs that break code (A description of two ways that your program crashes when it is run) Pseudocode Total CS110, Tatiana Harrison, CWU, HW 3: Conditionals, the switch constructor Points Available 20 10 10 10 10 20 5 5 5 5 100 Page 3 of 3 Page < 3 of 3 ZOOM +
Expert Answer:
Answer rating: 100% (QA)
Below is the Java code for the NumberDaysLeftThisYear program Ive also included pseudocode comments and descriptions of potential crashes as required ... View the full answer
Related Book For
Microeconomics An Intuitive Approach with Calculus
ISBN: 978-0538453257
1st edition
Authors: Thomas Nechyba
Posted Date:
Students also viewed these programming questions
-
QUIZ... Let D be a poset and let f : D D be a monotone function. (i) Give the definition of the least pre-fixed point, fix (f), of f. Show that fix (f) is a fixed point of f. [5 marks] (ii) Show that...
-
re Regular Languages and Finite Automata (a) Let L be the set of all strings over the alphabet {a, b} that end in a and do not contain the substring bb. Describe a deterministic finite automaton...
-
Two Amps are connected in series the first amplifier is an inverting amplifier and the second amplifier is a non-inverting amplifier, which of the following resistors produce a gain of -36? Amp1 (Ri...
-
The following financial information (in millions except for per share amounts) is for two major corporations for the three fiscal years ended December 31 as follows: Neither company has preferred...
-
Every fall, volunteers administer flu vaccine shots at a local supermarket. The pro-cess involves the following four steps: a. What are the bottleneck activity and maximum number of people who can be...
-
When we say that a photon is a "quantum of light," what does that mean? What is quantized?
-
1. For a company with operations in a difficult country, what would be the advantages of hiring manager from that country? What would be the disadvantages? 2. What would be the advantages of sending...
-
Draw DECISION TREE for the following structured English IF (Marks <50) THEN F ENDIF IF (Marks Between 50 and 59) THEN D ENDIF IF (Marks Between 60 and 74) THEN C ENDIF IF (Marks Between 75 and 89)...
-
The dispute about the building contract is eventually resolved. As part of the resolution of the dispute, a contract is formed with a builder and the project moves forward. As the project is...
-
Consider the following cases: Case Unit Price Unit Variable Cost Fixed Costs Depreciation 1 $ 3,000 $ 2,220 $ 15,000,000 $ 5,400,000 2 40 28 15,000 36,000 3 8 3.4 800 560 Ignore any tax...
-
Could you elaborate on the operational principles of forward and backward counting logic as applied to incremental encoders? How does each logic scheme facilitate the tracking and interpretation of...
-
Jean has decided it is time to buy a new battery for her car. Her choices are: First cost Guaranteed period Zappo $48 12 Kicko $78 24 Jean believes the batteries can be expected to last only for a...
-
The risk free rate is 4%, and the required return on the market is 12%. a) What is the required return on an asset with a beta of 1.5? b) What is the reward/risk ratio given the required rate of...
-
Can you explain the principles and algorithms used in deadlock detection and avoidance strategies within operating systems, highlighting the challenges of resource allocation and synchronization in...
-
A friend who is an engineer for a recreational vehicle manufacturer calls you and describes corrosion at the interface between the Type 321 stainless steel walls and the Type 347 stainless steel weld...
-
Find the radius of convergence in two ways: (a) Directly by the CauchyHadamard formula in Sec. 15.2. (b) From a series of simpler terms by using Theorem 3 or Theorem 4.
-
The introduction to intertemporal budgeting in this chapter can be applied to thinking about the pricing of basic financial assets. The assets we will consider will differ in terms of when they pay...
-
Exploring the Difference between Willingness to Pay and Willingness to Accept: Suppose you and I are identical in every way same exogenous income, same tastes over pizza and other goods. The only...
-
It is widely recognized that the social security systems in many western democracies will face substantial shortfalls between anticipated revenues and promised benefits over the coming decades. A:...
-
Define a closely held corporation.
-
Explain the role played by a board of directors of a corporation.
-
Explain how corporations provide limited liability to their owners.
Study smarter with the SolutionInn App