0% found this document useful (0 votes)
72 views2 pages

Annotated Birthday 3.java

This Java program takes a user's current date and birthday as input to calculate the number of absolute days until their next birthday. It contains methods to get the month and date from the user, determine the number of days in each month, count the total number of days between two dates, print the dates and counts, and output a message about how many days remain until the user's next birthday.

Uploaded by

Tasnim Mahi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
72 views2 pages

Annotated Birthday 3.java

This Java program takes a user's current date and birthday as input to calculate the number of absolute days until their next birthday. It contains methods to get the month and date from the user, determine the number of days in each month, count the total number of days between two dates, print the dates and counts, and output a message about how many days remain until the user's next birthday.

Uploaded by

Tasnim Mahi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

/* this program computes the number of absolute days until your bday */

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 setermines the number of days in each month.


public static int numOfDaysInMonth(int month){
if (month==1 || month ==3){
return 31;
}
else if (month==2){
return 28;
}
else if (month==4 || month ==6){
return 30;
}
else if (month==5 || month ==7){
return 31;
}
else if (month==8 || month==10){
return 31;
}
else if (month==9 || month ==11){
return 30;
}
else{
return 31;
}

// 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.");
}
}

You might also like