It compiles fine if the user inputs mm/dd/yyyy, but if they input m/d/yyyy it wont work. Any ideas? I am going to upload the directions that I was given. Code is all done just a couple errors : (
Thanks in advance!
Joey
import java.util.Scanner; public class Activity2 { public static void main(String[]args) { Scanner sc = new Scanner(System.in); String date, year; int day, month; boolean leapYear; System.out.println("Please enter a date in the format of mm/dd/yyyy."); date = sc.nextLine(); day= Integer.parseInt(formatDay(date)); month= flag(formatMonth(date)); year=formatYear(date); leapYear=leapYear(date); switch(month) { case 1:System.out.println("The date is: January "+day+", "+year); break; case 2:if(day<=28){ System.out.println("The date is: February "+day+", "+year); } break; case 3:System.out.println("The date is: March "+day+", "+year); break; case 4:System.out.println("The date is: April "+day+", "+year); break; case 5:System.out.println("The date is: May "+day+", "+year); break; case 6:System.out.println("The date is: June "+day+", "+year); break; case 7:System.out.println("The date is: July "+day+", "+year); break; case 8:System.out.println("The date is: August "+day+", "+year); break; case 9:System.out.println("The date is: September "+day+", "+year); break; case 10:System.out.println("The date is: October "+day+", "+year); break; case 11:System.out.println("The date is: November "+day+", "+year); break; case 12:System.out.println("The date is: December "+day+", "+year); break; default: System.out.println("What planet are you living on with that kind of date? Try again!"); } System.out.println("It is "+leapYear+" that the year "+year+" is a leap year."); } public static String formatDay(String q) { String day; int d; day =q.substring(3,5); d=Integer.parseInt(day); return day; } public static int formatMonth(String q) { String month = q.substring(0,2); int m = flag(Integer.parseInt(month)); return m; } public static int flag(int month) { if(month==1) month=1; if(month==2) month=2; if(month==3) month=3; if(month==4) month=4; if(month==5) month=5; if(month==6) month=6; if(month==7) month=7; if(month==8) month=8; if(month==9) month=9; if(month==10) month=10; if(month==11) month=11; if(month==12) month=12; return month; } public static String formatYear(String q) { String year; year = q.substring(6,10); return year; } public static boolean leapYear(String q) { String year=q.substring(6,10); int leap=Integer.parseInt(year); { if ((leap%4)==0 && (leap%100)!=0) return true; if ((leap%4)==0&&(leap%100)==0&&(leap%400)==0) return true; else return false; } } }