I'm supposed to calculate and display the number of total days, and then the number of months, and days from now (when the program is run) to when the person’s next birthday is (no leap year). Here is my code:
import java.util.Scanner; import java.text.*; import java.lang.System; import java.util.Date; import java.util.Calendar; public class CSCD210Lab3 { public static void main (String [] args) { Scanner userInput = new Scanner(System.in); //Declare Variables String nameFirst; char firstLetter; String nameMiddle; String nameLast; char lastLetter; String genders; String genderName; String nameReplace; String birthMonth; String birthDate; String birthYear; long birthMillis; long systemMillis; long diffMillis; int daysFromMillis; int birthMonthInt; int birthDayInt; int birthYearInt; //Get User Input System.out.print("Please Enter Your Full Name(Including Middle Name): ") ; nameFirst = userInput.next(); nameMiddle = userInput.next(); nameLast = userInput.next(); firstLetter = nameFirst.charAt(0); lastLetter = nameLast.charAt(nameLast.length()-1); userInput.nextLine() ; System.out.print("Please Enter Your Birthday in the Following Format: MM DD YYYY: ") ; birthMonth = userInput.next(); birthDate = userInput.next(); birthYear = userInput.next(); birthMonthInt = Integer.parseInt(birthMonth); birthDayInt = Integer.parseInt(birthDate); birthYearInt = Integer.parseInt(birthYear); Calendar myCalendar = Calendar.getInstance(); myCalendar.set(birthYearInt, birthDayInt, birthYearInt); birthMillis = myCalendar.getTimeInMillis(); systemMillis = System.currentTimeMillis(); diffMillis = (systemMillis - birthMillis); daysFromMillis = (int)(diffMillis / (86400000)); userInput.nextLine() ; DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy"); Date date = new Date(); System.out.print("Please Enter Your Gender as M or F: ") ; genders = userInput.next(); char gender = genders.charAt(0); genderName = nameFirst + " " + nameMiddle + " " + nameLast; nameReplace = genderName.replaceAll(genders, "?"); userInput.nextLine(); System.out.println(); System.out.println("The First Letter of Your First Name is: " + firstLetter) ; System.out.println("The Last Letter of Your Name is: "+ lastLetter); System.out.println("Your Middle Name is: " + nameMiddle); System.out.println("Your Name With the Last Name First is: "+ nameLast + ", "+ nameFirst + " " +nameMiddle); System.out.println("Today's Date is: "+dateFormat.format(date)); System.out.println("Your Name With The Letter of Your Gender Replacing the Same Letters In Your Name is: "+ nameReplace); System.out.println("Your birthday is "+daysFromMillis+ " days from now, or "+"months and "+" days."); } }
When I call daysFromMillis in the print statement, if I enter in a birthday of 02/17/1993, I will get an answer of "your birthday is 5435 days from now." What am I doing wrong?