Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For this programming task, you'll use conditional control statements (if, if-else, if-else-if, etc.), as well as the switch statement. Your program will prompt the user

For this programming task, you'll use conditional control statements (if, if-else, if-else-if, etc.), as well as the switch statement. 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 since the beginning of the year till the date of the year, all three specified by the user.

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 since the beginning the year. An example of a pseudo-code for the entire program is given to you.

image text in transcribed

image text in transcribed

// declare variables dayOfMonth and year of type int // declare variables month Name of type String, dayOfMonth and year of type int. // 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 daysSoFarln Year of type int, and assign it the value o // 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/ 1. If the year is evenly divisible by 4, go to step 2. Otherwise, go to step 5. 1/ 2. If the year is evenly divisible by 100, go to step 3. Otherwise, go to step 4. 1/ 3. If the year is evenly divisible by 400, go to step 4. Otherwise, go to step 5. 1/ 4. The year is a leap year (it has 366 days). 1/ 5. The year is not a leap year (it has 365 days). // Use a switch statement to determine the number of days since beginning of the year. // For example, December 1 would be day 335 in a leap year and day 334 in a non-leap year. // days, so daysSoFarln Year = 335 + dayOfMonth - 1. // For November, there are 305 days from the beginning of the year, so 11 days SoFarln Year = 305 + dayOfMonth - 1 in a leap year, 304 + dayOfMonth - 1 - in a non-leap year. // For January, it doesn't matter if a year is a leap year, so 17 daysSoFarln Year = dayOfMonth - 1.. 11 output the correct text (don't forget plural vs singular), to indicate how many complete days are so far in the year. switch(monthNamex case "January: // on January 11 daysSoFarln Year = 0 days SoFarin Year = dayOfMonth - 1, break; case "February"://on February 18 daysSoFarln Year = 31 daysSoFarin Year = 31; daysSoFarln Year += dayOfMonth - 1; break; case "March": // on March 1, 31 + 29 days in a leap year, otherwise + 28 Figure 3 To test your code, be sure to use a variety of month/day/ycar 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): Whal month is il? December What day of the month is it? 30 What year is it? 2007 There are 363 complete days since the beginning of the non-leap year 2007. Sample invocation 2 (2008 is a leap year, and date input is in January): What month is it? January CS110, Tallinna HUMSOLL, CWU, HW 3 : Conditionals, the switch constructor Page 2 of 3 What day of the month is it? 2 what year is it? 2009 There is 1 complele day since the beginning of 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 14 complete days since the beginning of the non-leap year 2009

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Application And Administration

Authors: Michael Mannino, Michael V. Mannino

2nd Edition

0072880678, 9780072880670

More Books

Students also viewed these Databases questions

Question

=+d. The price of sports utility vehicles rises.

Answered: 1 week ago

Question

LO13.1 List the characteristics of monopolistic competition.

Answered: 1 week ago