Annotated Birthday 3.java
Annotated Birthday 3.java
import java.util.*;
public class Birthday{
public static void main(String[]args){
Scanner s = new Scanner (System.in);
intro();
int CurrMonth = getInfoAbtMonth(s);
int CurrDate = getInfoAbtDay(s, CurrMonth);
int numCurrDayz = DaysTillCount(CurrMonth, CurrDate);
printAbsDays( CurrMonth ,CurrDate, numCurrDayz);
System.out.println();
int BirthMonth = getInfoAbtMonth(s);
int BirthDate = getInfoAbtDay(s, BirthMonth);
int numBdayz = DaysTillCount(BirthMonth, BirthDate);
printAbsDays( BirthMonth,BirthDate,numBdayz);
System.out.println();
getReport (numCurrDayz, numBdayz);
}
// prints introduction portion of the prgram that decribes the overall
funtionality of the program
public static void intro(){
System.out.println("This program tells you how many days");
System.out.println("it will be until your next birthday.");
System.out.println();
}
// gets information from the user about their birth month.
public static int getInfoAbtMonth(Scanner s){
System.out.print("What is the month (1-12)? ");
int month = s.nextInt();
return month;
}
// gets information from the user about their birth date
public static int getInfoAbtDay(Scanner s, int month){
System.out.print("What is the day (1-"+numOfDaysInMonth(month)+")? ");
int day = s.nextInt();
return day;
}
// this method counts the absolute number of days when you pass a date.
public static int DaysTillCount(int month, int day){
int countDayz= 0;
for (int i = 1; i<month; i++){
countDayz+= numOfDaysInMonth(i);
}
return countDayz+=day;
}
// this method prints the number of absolute days after each month.
public static void printAbsDays (int month , int day , int AbsDays){
System.out.println(month + "/"+ day + " is day"+ " #"+ AbsDays + " of
365.");
}
// this method gives you the number of absoulute days between the current
date and your birthday
public static void getReport (int currDayCount, int BdayCount){
if (BdayCount == currDayCount ){
System.out.println("Happy birthday!");
}
else if ((BdayCount-currDayCount)==1){
System.out.println("Wow, your birthday is tomorrow!");
}
else if (BdayCount>currDayCount){
System. out.println("Your next birthday is in " + (BdayCount-
currDayCount)+" days.");
}
else {
System.out.println("Your next birthday is in "+ (365- (currDayCount-
BdayCount))+" days.");
}
}