I am trying to write a program in java which will input the current date and the date of the user's birthday and then output how many days in till the users next birthday.
When attempting to compile my code I receive a "cannot find symbol- variable absolutepday" error. I have looked over my code many times and cannot figure out what is wrong. (I believe it has something to do with my scope for my variables but I am not sure)(I am a beginner)
How can I fix it so these variables are included in my scope?
Any help and advice is greatly appreciated!
Here is my code:
import java.util.Scanner;
public class BirthdayProject
{
//programs purpose
public static void initialstatement()
{
System.out.println("This program tells you how many days\nit will be until your next birthday.");
System.out.println();
}
//calculate absolute day of the year of todays date
public static int todaysdate()
{
int absolutepday = 0;
Scanner input = new Scanner(System.in);
System.out.println("Please enter today's date:");
System.out.print("What is the month (1-12)? ");
int pmonth= input.nextInt();
System.out.print("What is the day (1-31)? ");
int pday= input.nextInt();
if (pmonth == 1)
absolutepday = pday;
else if (pmonth == 2)
absolutepday = 31 + pday;
else if (pmonth == 3)
absolutepday = 59 + pday;
else if (pmonth == 4)
absolutepday = 90 + pday;
else if (pmonth == 5)
absolutepday = 120 + pday;
else if (pmonth == 6)
absolutepday = 151 + pday;
else if (pmonth == 7)
absolutepday = 181 + pday;
else if (pmonth == 8)
absolutepday = 212 + pday;
else if (pmonth == 9)
absolutepday = 243 + pday;
else if (pmonth == 10)
absolutepday = 273 + pday;
else if (pmonth == 11)
absolutepday = 304 + pday;
else if (pmonth == 12)
absolutepday = 334 + pday;
System.out.println(pmonth + "/" + pday + " is day #" + absolutepday + " of 365");
System.out.println();
return absolutepday;
}
//calculate absolute day of the year of the users birthday
public static int birthdaydate()
{
int absolutebday = 0;
Scanner input = new Scanner(System.in);
System.out.println("Please enter your birthday:");
System.out.print("What is the month (1-12)? ");
int bimonth= input.nextInt();
System.out.print("What is the day (1-30)? ");
int biday= input.nextInt();
if (bimonth == 1)
absolutebday = biday;
else if (bimonth == 2)
absolutebday = 31 + biday;
else if (bimonth == 3)
absolutebday = 59 + biday;
else if (bimonth == 4)
absolutebday = 90 + biday;
else if (bimonth == 5)
absolutebday = 120 + biday;
else if (bimonth == 6)
absolutebday = 151 + biday;
else if (bimonth == 7)
absolutebday = 181 + biday;
else if (bimonth == 8)
absolutebday = 212 + biday;
else if (bimonth == 9)
absolutebday = 243 + biday;
else if (bimonth == 10)
absolutebday = 273 + biday;
else if (bimonth == 11)
absolutebday = 304 + biday;
else if (bimonth == 12)
absolutebday = 334 + biday;
System.out.println(bimonth + "/" + biday +" is day #" + absolutebday + " of 365.");
System.out.println();
return absolutebday;
}
//calculate how many days intill the users next birthday
public static void main()
{
initialstatement();
todaysdate();
birthdaydate();
int absolutedaystillbday = (absolutepday-absolutebday)+(absolutepmonth-absolutebmonth);
if (absolutedaystillbday == 0)
System.out.println("Happy Birthday!");
else if (absolutedaystillbday == 1)
System.out.println("Wow, your birthday is tomorrow!");
else if (absolutedaystillbday > 0)
System.out.println("Your next birthday is in " + absolutedaystillbday + "days.");
else if (absolutedaystillbday < 0)
System.out.print("Your next birthday is in " + (absolutedaystillbirthday + 365) + "days.");
}
}