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
-
2. Suppose that the amount of protein in certain type of energy bar is Normally Distributed with a mean of 8.5 grams with a standard deviation of 0.45 grams. Suppose that a random bar of this type is...
-
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...
-
Let A be a continuous random variable with pdf f(x) and cdf F(x). For a fixed number xo, define the function Prove that g(x) is a pdf. (Assume that F(xo) f(2)/1- F(zo)] 9(=) = {e)/t I < 10. %3D
-
Wine is an alcoholic beverage made from grapes. Criticize the following definitions in light of the eight rules for lexical definitions:
-
Which of the following statements about exercising leadership processes with information systems auditors is most likely to be false? a. An authoritarian leadership style will be most successful when...
-
The following direct quote exchange rates are found on the spot market today. a. Euro: $.9347 b. Israeli shekel: $.2586 c. British (U.K.) pound: $1.6544 d. Japanese yen: $.009423 Calculate the price...
-
Give the slope and y - intercept of the line whose equation is given below. Then graph the linear function.Give the slope and y - intercept of the line whose equation is given below. Then graph the...
-
Determine the optical path difference for the two waves A and B, both having vacuum wavelengths of 500 nm, depicted in Fig. P.7.6; the glass (n = 1.52) tank is filled with water (n = 1.33). If the...
-
Susin'n de usin'n du find the value.
-
What is entropy? Information systems staff often have a very high rate of turnover in their jobs. Is this a form of entropy in information systems? If so, how can concurrent auditing techniques be...
-
Outline the difference between the snapshot and extended record concurrent auditing techniques.
-
Describe two methods of removing the effects of ITF transactions and the relative advantages and disadvantages of each method.
-
Describe two methods of entering test data for an ITF application and discuss the relative advantages and disadvantages of each method.
-
Briefly describe the nature of ITF.
-
A division of Ditton Industries manufactures a deluxe toaster oven. Management has determined that the daily marginal cost function associated with producing these toaster ovens is given by C'(x) =...
-
Consider the reaction of acetic acid in water CH 3 CO 2 H(aq) + H 2 O(l) CH3CO 22 (aq) + H 3 O + (aq) where Ka 5 1.8 3 1025. a. Which two bases are competing for the proton? b. Which is the stronger...
-
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:...
-
Advertising is an important type of _________ competition that firms use to _________ the demand for their products.
-
Advertising may not only increase the demand facing a firm, it may also make the demand facing the firm more _________ if it convinces buyers the product is truly different. A more inelastic demand...
-
By making information about substitutes and prices less costly to acquire, advertising will increase the _________ in industries, which is good for consumers.
Study smarter with the SolutionInn App