Please help and thank you in advance. The language is Java. I have to write a program that takes and validates a date but it won't output the full date.   Here is my current code: import java.util.Scanner; public class P1  {   publicstaticvoidmain(String[]args)  { // project 1 // date input // date output   // Create a Scanner object to read from the keyboard. Scannerkeyboard=newScanner(System.in);   // Identifier declarations charmonth; intday; intyear; booleanisLeapyear; StringmonthName; intmaxDay;   // Asks user to input date System.out.println("Please enter month: "); month=(char)keyboard.nextInt(); System.out.println("Please enter day: "); day=keyboard.nextInt(); System.out.println("Please enter year: "); year=keyboard.nextInt();   // Formating months switch(month){   case1: monthName="January"; break; case2: monthName="February"; break; case3: monthName="March"; break; case4: monthName="April"; break; case5: monthName="May"; break; case6: monthName="June"; break; case7: monthName="July"; break; case8: monthName="August"; break; case9: monthName="September"; break; case10: monthName="October"; break; case11: monthName="November"; break; case12: monthName="December"; break;   default:monthName="Invalid month";   System.out.println("The month is "  +monthName);   // The second version must accept any integer between 1 and 12 if(month>=1&&month<=12)  {break;   }else{System.out.println("The month you have enertred in is invalid," +"please try again"); }   // Formating days if(month==1||month==3||month==5||month==7||  month==8||month==10||month==12) maxDay=31; elseif(month==4||month==6||month==9||month==11) maxDay=30; elseif(month==2); maxDay=28;   // validate input if(maxDay>=1&&maxDay<=31)   System.out.println("That date is valid"); else System.out.println("That number is invalid."); System.out.print("Enter a number in the " + "range of 1 through 31: "); maxDay=keyboard.nextInt();   // Formating year if(year>=1&&year<=99){ if(month==2&&day==29){ if((year+2000)%4==0){ break; }else{ System.out.println("Leap year, Cannot contain 29 days. Enter valid year again!"); } }else{                      break; } }   // Leap year isLeapyear=(year%4==0); isLeapyear=isLeapyear&&(year%100!=0); isLeapyear=isLeapyear||(year%400==0); System.out.println(isLeapyear);   // Output of full date System.out.println(month + " " + day + ", " + year); } } }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

Please help and thank you in advance.

The language is Java.

I have to write a program that takes and validates a date but it won't output the full date.

 

Here is my current code:

import java.util.Scanner;

public class P1 

{

 

publicstaticvoidmain(String[]args) 

{

// project 1

// date input

// date output

 

// Create a Scanner object to read from the keyboard.

Scannerkeyboard=newScanner(System.in);

 

// Identifier declarations

charmonth;

intday;

intyear;

booleanisLeapyear;

StringmonthName;

intmaxDay;

 

// Asks user to input date

System.out.println("Please enter month: ");

month=(char)keyboard.nextInt();

System.out.println("Please enter day: ");

day=keyboard.nextInt();

System.out.println("Please enter year: ");

year=keyboard.nextInt();

 

// Formating months

switch(month){

 

case1:

monthName="January";

break;

case2:

monthName="February";

break;

case3:

monthName="March";

break;

case4:

monthName="April";

break;

case5:

monthName="May";

break;

case6:

monthName="June";

break;

case7:

monthName="July";

break;

case8:

monthName="August";

break;

case9:

monthName="September";

break;

case10:

monthName="October";

break;

case11:

monthName="November";

break;

case12:

monthName="December";

break;

 

default:monthName="Invalid month";

 

System.out.println("The month is " 

+monthName);

 

// The second version must accept any integer between 1 and 12

if(month>=1&&month<=12) 

{break;

 

}else{System.out.println("The month you have enertred in is invalid,"

+"please try again");

}

 

// Formating days

if(month==1||month==3||month==5||month==7|| 

month==8||month==10||month==12)

maxDay=31;

elseif(month==4||month==6||month==9||month==11)

maxDay=30;

elseif(month==2);

maxDay=28;

 

// validate input

if(maxDay>=1&&maxDay<=31)

 

System.out.println("That date is valid");

else

System.out.println("That number is invalid.");

System.out.print("Enter a number in the " + "range of 1 through 31: ");

maxDay=keyboard.nextInt();

 

// Formating year

if(year>=1&&year<=99){

if(month==2&&day==29){

if((year+2000)%4==0){

break;

}else{

System.out.println("Leap year, Cannot contain 29 days. Enter valid year again!");

}

}else{

                     break;

}

}

 

// Leap year

isLeapyear=(year%4==0);

isLeapyear=isLeapyear&&(year%100!=0);

isLeapyear=isLeapyear||(year%400==0);

System.out.println(isLeapyear);

 

// Output of full date

System.out.println(month + " " + day + ", " + year);

}

}

}

 

### Task #1
Your first version must have at least the header information (see *Programming Assignments Requirements and Recommendations*) and be able to ask the user for input, accept the input, and produce output. For the first version, you may assume that the user is interested in only one date, say "01/01/2022," and no input error is possible. Then your program must output "January 1, 2022" if the user inputs 1, 1, and 22.

### Task #2
The second version must accept any integer between 1 and 12 as the first input, any integer between 1 and 31 as the second input, and any integer between 1 and 99 as the third input. No error check is required in this version. For example, if the user inputs 2, 31, 22, the program outputs "February 31, 2022."

### Task #3
The third version of the project must check inputs for correctness:

(a) The inputted numbers must be inside the eligible ranges. For instance, if the user inputs 15 as the first number, the program must stop with the corresponding error message.

(b) The number of eligible days must depend on the month. For example, the second input of 31 is not eligible if the first input was 4 (April).

(c) If the inputted year is a leap year, the number of eligible days in February must be 29. Feel free to use an example from Lecture 1b to define whether the year is leap or not.

The third version must output the message explaining the error and stop in case of any input error.

### Task #4 (optional)
You can make your program better if, instead of stopping after the wrong input, your program requests the new input until the correct one is provided. You need a loop statement to do so, but it is **not required**, and a program that stops in case of the input error will be considered correct.
Transcribed Image Text:### Task #1 Your first version must have at least the header information (see *Programming Assignments Requirements and Recommendations*) and be able to ask the user for input, accept the input, and produce output. For the first version, you may assume that the user is interested in only one date, say "01/01/2022," and no input error is possible. Then your program must output "January 1, 2022" if the user inputs 1, 1, and 22. ### Task #2 The second version must accept any integer between 1 and 12 as the first input, any integer between 1 and 31 as the second input, and any integer between 1 and 99 as the third input. No error check is required in this version. For example, if the user inputs 2, 31, 22, the program outputs "February 31, 2022." ### Task #3 The third version of the project must check inputs for correctness: (a) The inputted numbers must be inside the eligible ranges. For instance, if the user inputs 15 as the first number, the program must stop with the corresponding error message. (b) The number of eligible days must depend on the month. For example, the second input of 31 is not eligible if the first input was 4 (April). (c) If the inputted year is a leap year, the number of eligible days in February must be 29. Feel free to use an example from Lecture 1b to define whether the year is leap or not. The third version must output the message explaining the error and stop in case of any input error. ### Task #4 (optional) You can make your program better if, instead of stopping after the wrong input, your program requests the new input until the correct one is provided. You need a loop statement to do so, but it is **not required**, and a program that stops in case of the input error will be considered correct.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 5 images

Blurred answer
Knowledge Booster
Random Class and its operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education