import java.util.Scanner;
public class LabOverloading
{
private String mouth;
private int day;
private int year;
public void setDate(int mouthInt,int day,int year)
{
if (dateOK(mouthInt,day,year))
{
this.mouth=mouthString(mouthInt);
this.day=day;
this.year=year;
}
else
{
System.out.println("Fatal Error");
System.exit(0);
}
}
public void setDate(String mouthString,int day,int year)
{
if (dateOK(mouthString,day,year))
{
this.mouth=mouthString;
this.day=day;
this.year=year;
}
else
{
System.out.println("Fatal Error");
System.exit(0);
}
}
public void setDate(int year)
{
setDate(1,1,year);
}
private boolean dateOK(int mouthInt,int dayInt,int yearInt )
{
return ((mouthInt>=1)&&(mouthInt<=12)&&(dayInt>=1)&&(dayInt<=31)&&(yearInt>=1000)&&(yearInt<=9999));
}
private boolean dateOK(String mouthString,int dayInt,int yearInt )
{
return (mouthOK(mouthString)&&(dayInt>=1)&&(dayInt<=31)&&(yearInt>=1000)&&(yearInt<=9999));
}
private boolean mouthOK(String mouth)
{
return (mouth.equals("January")mouth.equals("February")mouth.equals("March")mouth.equals("April")mouth.equals("May")mouth.equals("June")mouth.equals("July")mouth.equals("August")mouth.equals("September")mouth.equals("October")mouth.equals("November")mouth.equals("Deceber"));
}
public void readInput()
{
boolean tryAgain=true;
Scanner keyboard=new Scanner(System.in);
while(tryAgain)
{
System.out.println("Enter mouth ,day and year.");
System.out.println("Do not use a comma.");
String mouthInput= keyboard.next();
int dayInput= keyboard.nextInt();
int yearInput= keyboard.nextInt();
if (dateOK(mouthInput,dayInput,yearInput))
{
setDate(mouthInput,dayInput,yearInput);
tryAgain=false;
}
else System.out.println("Illegal date. Reenter input");
}
}
public String mouthString(int mouthNumber)
{
switch(mouthNumber)
{
case 1: return "January";
case 2: return "February";
case 3: return "March";
case 4: return "April";
case 5: return "May";
case 6: return "June";
case 7: return "July";
case 8: return "August";
case 9: return "September";
case 10: return "October";
case 11: return "November";
case 12: return "Deceber";
default: System.out.println("Fatal Error");
System.exit(0); return "Error";
}
}
public String toString()
{
return year+"/"+mouth+"/"+day;
}
public static void main(String[] args)
{
LabOverloading date1=new LabOverloading(),
date2=new LabOverloading(),
date3=new LabOverloading();
date1.setDate(1,2,2008);
date2.setDate("February",2,2008);
date3.setDate(2008);
System.out.println(date1);
System.out.println(date2);
System.out.println(date3);
}
}