In: Computer Science
Writing 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, 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
month/day/year is a valid date. or month/day/year is an invalid date.
month = 5, day = 32, year =2014Observe the output of this program.
month = 9, day = 21, year = 2002Observe the output of this program.
Note: Could you plz go through this code and let me
know if u need any changes in this.Thank You
_________________
// DateValidorNot.java
import java.util.Scanner;
public class DateValidorNot {
public static void main(String[] args) {
housekeeping();
}
   private static void housekeeping() {
       int day, month, year;
       /*
       * Creating an Scanner class object
which is used to get the inputs
       * entered by the user
       */
       Scanner sc = new
Scanner(System.in);
       String date;
       System.out.print("Enter Date (in
MM/DD/YYYY format) :");
       date = sc.next();
       int indx1 =
date.indexOf("/");
       month =
Integer.parseInt(date.substring(0, indx1));
       int indx2 =
date.lastIndexOf("/");
       day =
Integer.parseInt(date.substring(indx1 + 1, indx2));
       year =
Integer.parseInt(date.substring(indx2 + 1));
endOfJob(day, month, year);
}
   private static void endOfJob(int day, int month,
int year) {
       boolean bool1 = false, bool2 =
false, bool3 = false;
       if (month >= 1 &&
month <= 12) {
           bool1 =
true;
       }
       if (day >= 1 && day
<= 31) {
           bool2 =
true;
       }
       if (year > 0) {
           bool3 =
true;
       }
       if (bool1 && bool2
&& bool3) {
          
System.out.println(month + "/" + day + "/" + year
          
        + " is valid date.");
       } else {
          
System.out.println(month + "/" + day + "/" + year
          
        + " is an invalid
date.");
       }
}
}
_________________________
Output#1:
Enter Date (in MM/DD/YYYY format) :5/32/2014
5/32/2014 is an invalid date.
_______________________
Output#2:
Enter Date (in MM/DD/YYYY format) :9/21/2002
9/21/2002 is valid date.
_______________________Thank You