subject

In this assignment, you add the input and output statements to a partially completed Java program. When completed, the user should be able to enter a year, a month, and a day to determine if the date is valid. Valid years are those that are greater than 0, valid months include the values 1 through 12, and valid days include the values 1 through 31.Instructions:Notice that variables have been declared for you. Write the simulated housekeeping() method that contains input statements to retrieve a year, a month, and a day from the user. Add statements to the simulated housekeeping() method that convert the String representation of the year, month, and day to ints. Include the output statements in the simulated endOfJob()method. The format of the output is as follows:month/day/year is a valid date. ormonth/day/year is an invalid date. Execute the program entering the following date:month = 5, day = 32, year =2014 Observe the output of this program. Execute the program entering the following date:month = 9, day = 21, year = 2002 Observe the output of this program./*** The java program BadDate. java that prompts* user to enter year, month and day and finds* if the user given date is valid or not* and display on a message dialog box.* *///BadDate. javaimport javax. swing. JOptionPane;public class BadDate{public static void main(String args[]){String yearString;String monthString;String dayString;// Get the year, then the month, then the day yearString=housekeeping("Enter a Year : ");monthString=housekeeping("Enter a Month : ");dayString=housekeeping("Enter a Day : ");//calling detailLoopdetailLoop(yearString, monthString, dayString);}private static void detailLoop(String yearString, String monthString, String dayString) {int year;int month;int day;boolean validDate = true;final int MIN_YEAR = 0, MIN_MONTH = 1, MAX_MONTH = 12, MIN_DAY = 1, MAX_DAY = 31;// Convert Strings to integersyear=Integer. parseInt(yearString);month=Integer. parseInt(monthString);day=Integer. parseInt(dayString);// Check to be sure date is validif( year <= MIN_YEAR ) // invalid yearvalidDate = false;else if ( month < MIN_MONTH || month > MAX_MONTH ) // invalid monthvalidDate = false;else if ( day < MIN_DAY || day > MAX_DAY ) // invalid dayvalidDate = false;String result="";// This is the work of the endOfJob() method// Test to see if date is valid and output date and whether it is valid or notif( validDate == true ){result="Date DD/MM/ : "+day+"/"+month+"/"+year+" is valid";JOptionPane. showMessageDialog(null, result, "Result", JOptionPane. INFORMATION_MESSAGE);}else{result=" Date DD/MM/ : "+day+"/"+month+"/"+year+" is in-valid";// Output statementJOptionPane. showMessageDialog(null, result, "Result", JOptionPane. INFORMATION_MESSAGE);}}//Method that takes a string and prompts user to enter inputprivate static String housekeeping(String prompt){String yearString=JOptionPane. showInputDialog(null, prompt); return yearString;} // end of main() method} // end of BadDate class

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 24.06.2019 13:30
Which of the following is not a “fatal four” event?
Answers: 2
question
Computers and Technology, 24.06.2019 16:00
How are roger williams, james oglethorpe, and william penn similar?
Answers: 3
question
Computers and Technology, 25.06.2019 05:30
Why are weather forecasts more reliable now compared of hundred years ago
Answers: 1
question
Computers and Technology, 25.06.2019 08:20
The main circuit board inside the system uit is called megaboard / true or false
Answers: 1
You know the right answer?
In this assignment, you add the input and output statements to a partially completed Java program. W...
Questions
question
Mathematics, 22.04.2021 22:40
question
Mathematics, 22.04.2021 22:40
question
Physics, 22.04.2021 22:40
question
Mathematics, 22.04.2021 22:40
question
Mathematics, 22.04.2021 22:40
Questions on the website: 13722360