I am a student who has just started programming (I am 1 and 1/2 weeks in), so please excuse me for my terrible code, I have not learned much yet.
I am writing this program to calculate how many days there are in till the user's next birthday, but am receiving a "cannot find symbol" error when I try to call my variables absolutepday, absolutebday, absolutepmonth, and absolutbmonth in my final method. I know this error involves scope, but for the life of me I cannot figure out how to fix this error.
I have read the other posts for this compiling error, but I still am not able to figure it out.
I would greatly appreciate if someone could simply tell me exactly how to fix this problem and explain why this is happened.
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(String[] args)
{
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.");
}
}
Thanks!