I got stucked on the part where I'm creating a method to convert(or compare) String month to int month.
And I wish to to use the equals method from the String class to compare to Strings for equality.
I don't know where to start.
Please help.
Thanks.
This is what I have so far (the entire thing)...not even sure if the rest if right.
import java.util.Scanner;
import java.util.Calendar;
import java.lang.String;
public class Birthday {
private static String month;
private static int monthInt;
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("In which year were you born?");
int year = scan.nextInt();
System.out.println("In which month were you born?");
String month = scan.next();
System.out.println("On what day of that month were you born?");
int date = scan.nextInt();
int monthInt = monthStringToInt(month); // month as an int.
// I put a little test here for the conversion b/w String month and int month...doesn't seem to work.
System.out.println(monthInt);
Calendar birthmonth = Calendar.getInstance();
birthmonth.set(Calendar.MONTH, monthInt);
Calendar birthyear = Calendar.getInstance();
birthyear.set( Calendar.YEAR, year );
Calendar birthdate = Calendar.getInstance();
birthdate.set( Calendar.DATE, date );
Calendar cal1 = Calendar.getInstance();
Calendar cal2 = Calendar.getInstance();
cal2.set(year, monthInt, date);
cal1.set(Calendar.YEAR, Calendar.MONTH, Calendar.DATE);
long milis1 = cal1.getTimeInMillis();
long milis2 = cal2.getTimeInMillis();
long diff = milis2 - milis1;
System.out.println(diff);
}
private static int monthStringToInt(String month) {
int January = Integer.valueOf (Calendar.JANUARY);
if (month.equals(January ))
{
monthInt = January;
}
//Similar to other 11 months
return monthInt;
}
}
This post has been edited by MmeLionHead: 16 February 2009 - 01:24 AM


Ask A New Question
Reply





MultiQuote







|