LaD 3-2Writing a Modular Program in Java In this lab, you add the input and outp
ID: 3907775 • Letter: L
Question
LaD 3-2Writing a Modular Program in Java In this lab, you add the input and output statements to a partially completed Java program. When completed, the user should be able to enter a year and then click the OK button, enter a month and then click the OK button, and enter a day and then click the OK button to determine if the date is valid. Valid years are those that are greater than O, valid months include the values 1 through 12, and valid days include the values 1 through 31. 1. Open the source code file named es using Notepad or the text editor of your choice. 45 46 2. Notice that variables have been declared for you. 3. Write the simulated heualespiaeo method that contains input statements to retrieve a year, a month and a day from the user. Add statements to the simulated houshepisg) method that convert the Strinc representation of the year, month, and day to ints. 5. Include the output statements in the simulated bgo method. The format of the output is as follows: or aontH Janyear is sn ialid date Save this source code file in a directory of your choice, and then make that directory your working directory. 6. 7. Compile the source code file Badist 8. Execute the program entering the following date: month s, day -32, year 2014. Record the output of this program. 9. Execute the program entering the following date: month 9, day "z1, year zo02. Record the output of this program.Explanation / Answer
Given below is the modified code for the question.
To indent code in eclipse , select code by pressing ctrl+a and then indent using ctrl+i
Please do rate the answer if it was helpful. Thank you
BadDate.java
-------
import javax.swing.JOptionPane;
public class BadDate {
static int year;
static int month;
static int day;
static final int MIN_YEAR=0, MIN_MONTH = 1, MAX_MONTH = 12, MIN_DAY = 1, MAX_DAY = 31;
static boolean validDate = true;
public static void main(String[] args) {
housekeeping();
detailLoop();
endOfJob();
}
private static void housekeeping(){
String yearString;
String monthString;
String dayString;
yearString = JOptionPane.showInputDialog("Enter year");
monthString = JOptionPane.showInputDialog("Enter month");
dayString = JOptionPane.showInputDialog("Enter day");
year = Integer.parseInt(yearString);
month = Integer.parseInt(monthString);
day = Integer.parseInt(dayString);
}
private static void detailLoop(){
if(year <= MIN_YEAR) //invalid year
validDate = false;
else if(month < MIN_MONTH || month > MAX_MONTH) //invalid month
validDate = false;
else if(day < MIN_DAY || day > MAX_DAY) //invalid day
validDate = false;
}
private static void endOfJob(){
if(validDate == true){
System.out.println(month +"/" + day +"/" + year +" is a valid date");
}
else {
System.out.println(month +"/" + day +"/" + year +" is an invalid date");
}
}
}
output
-----
9/21/2002 is a valid date
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.