Question: Finish the date validation (the code bellow) to include Leap Years 1 package strings; gm 3 import javax. swing.30ptionPane; gs 5 public class DateValidation 4
1 package strings; gm 3 import javax. swing.30ptionPane; gs 5 public class DateValidation 4 6 public static void main (Stringl] ar) rc 7 str 8String date; 9 int m,d,y,loc1,loc2; boolean valid = true; 12 13 14 15 16 17 18 19 2e I/user input date = JOptionPane.showInputDialog("Enter date m/d/y format"); 1/location of first slash loc! date . indexOf("/"); 10e2 = date . lastIndexOf("/"); I/get month, day and year m=Integer.parseInt(date.substring(8, lod)); d = Integer.parselnt(date.substring(10c1+1,1oe2)); 22 y Integer.parseInt (date.substring(loc2+1)); 23 24 25 26 if (m 28) 31 32 else if ((m==4 11 m=-6 11 m=11) && d > 3a) 34 35 if(valid) 36 37 else 38 39 40 30ptionPane.showMessageDialog(null,"Invalid date: "+ date); OptionPane.showMessageDialog(null, "Ininvalid date: " + date)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
