Create a birthday reminder program


Discuss the below:

I am having an bit of issue with the program I want to create a birthday reminder program that accepts the user name and birthday as an input and displays the following messages based on the user's birthday: I am trying to create birthday reminder program that accepts the user name and birthday as an input and displays one of the following messages based on the user's birthday In Java.

I figured out how to work with the dates. Right now all it does is prompt for user name and birthday, and then output the information back along with age in years and days.

I haven't yet accounted for leap years, so if the input birthday is a leap year or if the current date is a leap year, it's going to be off by a day or two.
Attached is the partial program I have written and compiled.

In the end I want the program to display these messages.
Birthday Messages to display

3) If a user's birthday is in two weeks from today's date, then the program should display. Hello , I am excited to let you know that you will be turning in days. Are you having any birthday plans? java.io.*;

import java.util.*;

import java.text.*;

public class HappyBirthday {

public static void main(String[] args) throws IOException

{

String sName, sYear, sMonth, sDay;

int iYearBorn, iMonthBorn, iDayBorn, iYearsOld, iDaysOld, iCalendarNowDayOfYear, iCalendarBdayDayOfYear, iCalendarNowYear, iCalendarBdayYear;

BufferedReader dataIn= new BufferedReader(new InputStreamReader(System.in));

System.out.println("Please enter your name.");

sName = dataIn.readLine();

System.out.println("Please enter the 4 digit year you were born.");

sYear = dataIn.readLine();

iYearBorn = Integer.parseInt(sYear);

System.out.println("Please enter the numerical month you were born.");

sMonth = dataIn.readLine();

iMonthBorn = Integer.parseInt(sMonth);

System.out.println("Please enter the day you were born.");

sDay = dataIn.readLine();

iDayBorn = Integer.parseInt(sDay);

//create calendar called calendarNow and set it to the current time and date

GregorianCalendar calendarNow = new GregorianCalendar();

Date dateNow = calendarNow.getTime();

//long longNow = dateNow.getTime();

//create calendar called calendarBday and set it to the user's birthday (iMonthBorn-1 because Jan starts at 0)

GregorianCalendar calendarBday = new GregorianCalendar(iYearBorn, iMonthBorn-1, iDayBorn);

Date dateBday = calendarBday.getTime();

//long longBday = dateBday.getTime();

//create date format called df and output user's name and formatted birthday

DateFormat df = DateFormat.getDateInstance();

System.out.println("Hello " + sName + " you were born on " + df.format(dateBday));

//set variables to year and day of year by accessing those fields of the two calendars

iCalendarNowDayOfYear = calendarNow.get(Calendar.DAY_OF_YEAR);

iCalendarBdayDayOfYear = calendarBday.get(Calendar.DAY_OF_YEAR);

iCalendarNowYear = calendarNow.get(Calendar.YEAR);

iCalendarBdayYear = calendarBday.get(Calendar.YEAR);

//calculate number of years and days old and assign to variables

if (iCalendarNowDayOfYear >= iCalendarBdayDayOfYear) //if birthday has already occurred this year

{

iYearsOld = iCalendarNowYear - iCalendarBdayYear;

iDaysOld = (iCalendarNowDayOfYear - iCalendarBdayDayOfYear);

}

else //if birthday has not yet occurred this year

{

iYearsOld = (iCalendarNowYear - 1) - iCalendarBdayYear;

iDaysOld = (iCalendarNowDayOfYear + 365 - iCalendarBdayDayOfYear);

}

System.out.println("\nYou are " + iYearsOld + " years and " + iDaysOld + " days old");

}

}

Solution Preview :

Prepared by a verified Expert
JAVA Programming: Create a birthday reminder program
Reference No:- TGS01935762

Now Priced at $25 (50% Discount)

Recommended (90%)

Rated (4.3/5)