Get the day of the week & month in word from constructor into main with input
Hi
i need to modify this code to fit the requirement.....any help and sample would be appreciated..
For this program, i need to: take in day, month,year of a date as int argument, return the day of the week for the date entered in App()
In Main: call the App() to get the day of the week to display when user enter the date in dd/mm/yyyy
StringTokenizer is required for this program.
- How can the arguments pass back to main by returning of month & day of the week?
- Program cant take in int and return as string
- Date cant display day of the week
Program output: 29 Aug 2010 is a Sunday
Code:
import java.util.*;
public class App2 {
private int day;
private int month;
private int year;
private int inputDay;
private int inputMonth;
private int inputYear;
public static String App2(String day2, String month2, String year2) { // this is wrong should pass int in
String date = day2 + month2 + year2;
DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
try
{
Date today = df.parse(date);
System.out.println("Today = " + df.format(today));
}
catch(ParseException e)
{
}
if(month2.equals("01") || month2.equals("1")){month2 = "January";}
else if(month2.equals("02") || month2.equals("2")){month2 = "February";}
else if(month2.equals("03") || month2.equals("3")){month2 = "March";}
else if(month2.equals("04") || month2.equals("4")){month2 = "April";}
else if(month2.equals("05") || month2.equals("5")){month2 = "May";}
else if(month2.equals("06") || month2.equals("6")){month2 = "June";}
else if(month2.equals("07") || month2.equals("7")){month2 = "July";}
else if(month2.equals("08") || month2.equals("8")){month2 = "August";}
else if(month2.equals("09") || month2.equals("9")){month2 = "September";}
else if(month2.equals("10")){month2 = "October";}
else if(month2.equals("11")){month2 = "November";}
else if(month2.equals("12")){month2 = "December";}
return month2; // can only return month, how abt day of week?
}
public static void main (String [ ] args){
Scanner sc = new Scanner(System.in);
System.out.print("Enter the date in dd/mm/yyyy: ");
String date = sc.nextLine();
StringTokenizer st = new StringTokenizer(date, "/");
String day = st.nextToken();
String month = st.nextToken();
String year = st.nextToken();
App2(day, month, year);
String test = App2(day, month, year);
System.out.print(test); //can get month Aug
}
}