/* Program to print the day of the date entered by the user
in the form of dd-MON-2014 for the year 2014 only */
import java.io.*;
public class dayofdate
{
public static void main(String args[])throws IOException
{
InputStreamReader read = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(read);
String dt = "", dd, mnth;
int dd1, res;
System.out.println("Enter the date : (dd-MON-2014)");
dt=in.readLine();
//fetching the dd of the given date
dd=dt.substring(0,2);
dd1=Integer.parseInt(dd);
res=dd1%7;
//fetching the mon of the given date
mnth=dt.substring(3,6);
mnth=mnth.toUpperCase();
// Fetching the day for the month of January or October
if(mnth.equals("JAN") || mnth.equals("OCT"))
{
if(dd1>0 && dd1<=31)
{
if(res==1)
System.out.println(dt + " is Wednesday. ");
else if(res==2)
System.out.println(dt + " is Thursday. ");
else if(res==3)
System.out.println(dt + " is Friday. ");
else if(res==4)
System.out.println(dt + " is Saturday. ");
else if(res==5)
System.out.println(dt + " is Sunday. ");
else if(res==6)
System.out.println(dt + " is Monday. ");
else
System.out.println(dt + " is Tuesday. ");
}
else
{
if(mnth.equals("JAN"))
System.out.println(dt + " : Invalid date!!! January has dates from 1 to 31 only ");
if(mnth.equals("OCT"))
System.out.println(dt + " : Invalid date!!! October has dates from 1 to 31 only ");
}
}
// Fetching the day for the month of February or March or November
else if(mnth.equals("FEB") || mnth.equals("MAR") || mnth.equals("NOV"))
{
if((mnth.equals("FEB") && dd1>0 && dd1<=28) || (mnth.equals("MAR") && dd1>0 && dd1<=30) || (mnth.equals("NOV") && dd1>0 && dd1<=30))
{
if(res==1)
System.out.println(dt + " is Saturday. ");
else if(res==2)
System.out.println(dt + " is Sunday. ");
else if(res==3)
System.out.println(dt + " is Monday. ");
else if(res==4)
System.out.println(dt + " is Tuesday. ");
else if(res==5)
System.out.println(dt + " is Wednesday. ");
else if(res==6)
System.out.println(dt + " is Thursday. ");
else
System.out.println(dt + " is Friday. ");
}
else
{
if(mnth.equals("FEB"))
System.out.println(dt + " : Invalid date!!! February has dates from 1 to 28 ");
if(mnth.equals("MAR"))
System.out.println(dt + " : Invalid date!!! March has dates from 1 to 30 ");
if(mnth.equals("NOV"))
System.out.println(dt + " : Invalid date!!! November has dates from 1 to 30 ");
}
}
// Fetching the day for the month of April or July
else if(mnth.equals("APR") || mnth.equals("JUL"))
{
if(dd1>0 && dd1<=30)
{
if(res==1)
System.out.println(dt + " is Tuesday. ");
else if(res==2)
System.out.println(dt + " is Wednesday. ");
else if(res==3)
System.out.println(dt + " is Thursday. ");
else if(res==4)
System.out.println(dt + " is Friday. ");
else if(res==5)
System.out.println(dt + " is Saturday. ");
else if(res==6)
System.out.println(dt + " is Sunday. ");
else
System.out.println(dt + " is Monday. ");
}
else
{
if(mnth.equals("APR"))
System.out.println(dt + " : Invalid date!!! April has dates from 1 to 30 only ");
if(mnth.equals("JUL"))
System.out.println(dt + " : Invalid date!!! July has dates from 1 to 30 only ");
}
}
// Fetching the day for the month of May
else if(mnth.equals("MAY"))
{
if(dd1>0 && dd1<=31)
{
if(res==1)
System.out.println(dt + " is Thursday. ");
else if(res==2)
System.out.println(dt + " is Friday. ");
else if(res==3)
System.out.println(dt + " is Satday. ");
else if(res==4)
System.out.println(dt + " is Sunday. ");
else if(res==5)
System.out.println(dt + " is Monday. ");
else if(res==6)
System.out.println(dt + " is Tuesday. ");
else
System.out.println(dt + " is Wednesday. ");
}
else
{
if(mnth.equals("MAY"))
System.out.println(dt + " : Invalid date!!! May has dates from 1 to 31 only ");
}
}
// Fetching the day for the month of June
else if(mnth.equals("JUN"))
{
if(dd1>0 && dd1<=30)
{
if(res==1)
System.out.println(dt + " is Sunday. ");
else if(res==2)
System.out.println(dt + " is Monday. ");
else if(res==3)
System.out.println(dt + " is Tuesday. ");
else if(res==4)
System.out.println(dt + " is Wednesday. ");
else if(res==5)
System.out.println(dt + " is Thursday. ");
else if(res==6)
System.out.println(dt + " is Friday. ");
else
System.out.println(dt + " is Saturday. ");
}
else
{
if(mnth.equals("JUN"))
System.out.println(dt + " : Invalid date!!! June has dates from 1 to 30 only ");
}
}
// Fetching the day for the month of August
else if(mnth.equals("AUG"))
{
if(dd1>0 && dd1<=30)
{
if(res==1)
System.out.println(dt + " is Friday. ");
else if(res==2)
System.out.println(dt + " is Saturday. ");
else if(res==3)
System.out.println(dt + " is Sunday. ");
else if(res==4)
System.out.println(dt + " is Monday. ");
else if(res==5)
System.out.println(dt + " is Tuesday. ");
else if(res==6)
System.out.println(dt + " is Wednesday. ");
else
System.out.println(dt + " is Thursday. ");
}
else
{
if(mnth.equals("AUG"))
System.out.println(dt + " : Invalid date!!! August has dates from 1 to 30 only ");
}
}
// Fetching the day for the month of September or December
else if(mnth.equals("SEP") || mnth.equals("DEC"))
{
if((mnth.equals("SEP") && dd1>0 && dd1<=30) || (mnth.equals("DEC") && dd1>0 && dd1<=31))
{
if(res==1)
System.out.println(dt + " is Monday. ");
else if(res==2)
System.out.println(dt + " is Tuesday. ");
else if(res==3)
System.out.println(dt + " is Wednesday. ");
else if(res==4)
System.out.println(dt + " is Thursday. ");
else if(res==5)
System.out.println(dt + " is Friday. ");
else if(res==6)
System.out.println(dt + " is Saturday. ");
else
System.out.println(dt + " is Sunday. ");
}
else
{
if(mnth.equals("SEP"))
System.out.println(dt + " : Invalid date!!! September has dates from 1 to 30 only ");
if(mnth.equals("DEC"))
System.out.println(dt + " : Invalid date!!! December has dates from 1 to 31 only ");
}
}
// Validating month name
else
System.out.println(dt + " : Invalid month!!! Enter the correct month ");
} // end of main
}
in the form of dd-MON-2014 for the year 2014 only */
import java.io.*;
public class dayofdate
{
public static void main(String args[])throws IOException
{
InputStreamReader read = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(read);
String dt = "", dd, mnth;
int dd1, res;
System.out.println("Enter the date : (dd-MON-2014)");
dt=in.readLine();
//fetching the dd of the given date
dd=dt.substring(0,2);
dd1=Integer.parseInt(dd);
res=dd1%7;
//fetching the mon of the given date
mnth=dt.substring(3,6);
mnth=mnth.toUpperCase();
// Fetching the day for the month of January or October
if(mnth.equals("JAN") || mnth.equals("OCT"))
{
if(dd1>0 && dd1<=31)
{
if(res==1)
System.out.println(dt + " is Wednesday. ");
else if(res==2)
System.out.println(dt + " is Thursday. ");
else if(res==3)
System.out.println(dt + " is Friday. ");
else if(res==4)
System.out.println(dt + " is Saturday. ");
else if(res==5)
System.out.println(dt + " is Sunday. ");
else if(res==6)
System.out.println(dt + " is Monday. ");
else
System.out.println(dt + " is Tuesday. ");
}
else
{
if(mnth.equals("JAN"))
System.out.println(dt + " : Invalid date!!! January has dates from 1 to 31 only ");
if(mnth.equals("OCT"))
System.out.println(dt + " : Invalid date!!! October has dates from 1 to 31 only ");
}
}
// Fetching the day for the month of February or March or November
else if(mnth.equals("FEB") || mnth.equals("MAR") || mnth.equals("NOV"))
{
if((mnth.equals("FEB") && dd1>0 && dd1<=28) || (mnth.equals("MAR") && dd1>0 && dd1<=30) || (mnth.equals("NOV") && dd1>0 && dd1<=30))
{
if(res==1)
System.out.println(dt + " is Saturday. ");
else if(res==2)
System.out.println(dt + " is Sunday. ");
else if(res==3)
System.out.println(dt + " is Monday. ");
else if(res==4)
System.out.println(dt + " is Tuesday. ");
else if(res==5)
System.out.println(dt + " is Wednesday. ");
else if(res==6)
System.out.println(dt + " is Thursday. ");
else
System.out.println(dt + " is Friday. ");
}
else
{
if(mnth.equals("FEB"))
System.out.println(dt + " : Invalid date!!! February has dates from 1 to 28 ");
if(mnth.equals("MAR"))
System.out.println(dt + " : Invalid date!!! March has dates from 1 to 30 ");
if(mnth.equals("NOV"))
System.out.println(dt + " : Invalid date!!! November has dates from 1 to 30 ");
}
}
// Fetching the day for the month of April or July
else if(mnth.equals("APR") || mnth.equals("JUL"))
{
if(dd1>0 && dd1<=30)
{
if(res==1)
System.out.println(dt + " is Tuesday. ");
else if(res==2)
System.out.println(dt + " is Wednesday. ");
else if(res==3)
System.out.println(dt + " is Thursday. ");
else if(res==4)
System.out.println(dt + " is Friday. ");
else if(res==5)
System.out.println(dt + " is Saturday. ");
else if(res==6)
System.out.println(dt + " is Sunday. ");
else
System.out.println(dt + " is Monday. ");
}
else
{
if(mnth.equals("APR"))
System.out.println(dt + " : Invalid date!!! April has dates from 1 to 30 only ");
if(mnth.equals("JUL"))
System.out.println(dt + " : Invalid date!!! July has dates from 1 to 30 only ");
}
}
// Fetching the day for the month of May
else if(mnth.equals("MAY"))
{
if(dd1>0 && dd1<=31)
{
if(res==1)
System.out.println(dt + " is Thursday. ");
else if(res==2)
System.out.println(dt + " is Friday. ");
else if(res==3)
System.out.println(dt + " is Satday. ");
else if(res==4)
System.out.println(dt + " is Sunday. ");
else if(res==5)
System.out.println(dt + " is Monday. ");
else if(res==6)
System.out.println(dt + " is Tuesday. ");
else
System.out.println(dt + " is Wednesday. ");
}
else
{
if(mnth.equals("MAY"))
System.out.println(dt + " : Invalid date!!! May has dates from 1 to 31 only ");
}
}
// Fetching the day for the month of June
else if(mnth.equals("JUN"))
{
if(dd1>0 && dd1<=30)
{
if(res==1)
System.out.println(dt + " is Sunday. ");
else if(res==2)
System.out.println(dt + " is Monday. ");
else if(res==3)
System.out.println(dt + " is Tuesday. ");
else if(res==4)
System.out.println(dt + " is Wednesday. ");
else if(res==5)
System.out.println(dt + " is Thursday. ");
else if(res==6)
System.out.println(dt + " is Friday. ");
else
System.out.println(dt + " is Saturday. ");
}
else
{
if(mnth.equals("JUN"))
System.out.println(dt + " : Invalid date!!! June has dates from 1 to 30 only ");
}
}
// Fetching the day for the month of August
else if(mnth.equals("AUG"))
{
if(dd1>0 && dd1<=30)
{
if(res==1)
System.out.println(dt + " is Friday. ");
else if(res==2)
System.out.println(dt + " is Saturday. ");
else if(res==3)
System.out.println(dt + " is Sunday. ");
else if(res==4)
System.out.println(dt + " is Monday. ");
else if(res==5)
System.out.println(dt + " is Tuesday. ");
else if(res==6)
System.out.println(dt + " is Wednesday. ");
else
System.out.println(dt + " is Thursday. ");
}
else
{
if(mnth.equals("AUG"))
System.out.println(dt + " : Invalid date!!! August has dates from 1 to 30 only ");
}
}
// Fetching the day for the month of September or December
else if(mnth.equals("SEP") || mnth.equals("DEC"))
{
if((mnth.equals("SEP") && dd1>0 && dd1<=30) || (mnth.equals("DEC") && dd1>0 && dd1<=31))
{
if(res==1)
System.out.println(dt + " is Monday. ");
else if(res==2)
System.out.println(dt + " is Tuesday. ");
else if(res==3)
System.out.println(dt + " is Wednesday. ");
else if(res==4)
System.out.println(dt + " is Thursday. ");
else if(res==5)
System.out.println(dt + " is Friday. ");
else if(res==6)
System.out.println(dt + " is Saturday. ");
else
System.out.println(dt + " is Sunday. ");
}
else
{
if(mnth.equals("SEP"))
System.out.println(dt + " : Invalid date!!! September has dates from 1 to 30 only ");
if(mnth.equals("DEC"))
System.out.println(dt + " : Invalid date!!! December has dates from 1 to 31 only ");
}
}
// Validating month name
else
System.out.println(dt + " : Invalid month!!! Enter the correct month ");
} // end of main
}
No comments:
Post a Comment