Computers and Technology

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

answer
Answers: 1

Other questions on the subject: Computers and Technology

image
Computers and Technology, 23.06.2019 02:00, HannahVance99
In the context of an internet connection, llc stands for leased line connection liability limited company local loop complex local loop carrier
Answers: 1
image
Computers and Technology, 23.06.2019 04:31, caseypearson377
Acloud service provider uses the internet to deliver a computing environment for developing, running, and managing software applications. which cloud service model does the provider offer? a. iaas b. caas c. maas d. paas e. saas
Answers: 1
image
Computers and Technology, 23.06.2019 06:30, darlene93
You are consulting for a beverage distributor who is interested in determining the benefits it could achieve from implementing new information systems. what will you advise as the first step?
Answers: 1
image
Computers and Technology, 23.06.2019 23:30, cam961
What are "open-loop" and "closed-loop" systems
Answers: 1
Do you know the correct answer?
In this assignment, you add the input and output statements to a partially completed Java program. W...

Questions in other subjects:

Konu
English, 10.01.2020 11:31
Konu
Mathematics, 10.01.2020 11:31