0

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.");
    }
}
John B.
  • 35
  • 2
  • 4
    You problem is in your `whattoprint` method. `absolutepday` and `absolutebday` aren't in that method's scope. – ifvictr Oct 16 '16 at 23:42
  • 2
    Reading the error should be your first course of action. It's pretty straightforward – Andrew Li Oct 16 '16 at 23:43
  • Please look at [What does a “Cannot find symbol” compilation error mean?](http://stackoverflow.com/questions/25706216/what-does-a-cannot-find-symbol-compilation-error-mean) – Hovercraft Full Of Eels Oct 16 '16 at 23:45
  • How can I make it so that these variables are in my methods scope? – John B. Oct 16 '16 at 23:49
  • I looked at the other article and still cannot figure it out. – John B. Oct 16 '16 at 23:56
  • One way to fix it: Both `todaysdate` and `birthdaydate` return ints. Call them both from within `whattoprint` instead of `main` and assign their return values to their respective variables. This should be refactored, though. I'm not a Java dev, but there must be some sort of `datediff` method. – Steve Oct 17 '16 at 00:01
  • Still haven't been able to figure it out, would anyone be able to edit it to show me? – John B. Oct 17 '16 at 00:10
  • The question has been marked as closed [duplicate], so we can't propose answers and I don't have enough reputation points to edit the question directly. Even if I did though, it would be a "no-no" to edit it and put the answer directly in the question. – Steve Oct 17 '16 at 00:18

0 Answers0