我是初学者,我无法弄清楚为什么我收到这个编译错误?

时间:2016-10-17 02:33:51

标签: java variables compiler-errors

我是一名刚刚开始编程的学生(我是1周和半周),所以请原谅我的可怕代码,我还没有学到很多东西。

我正在编写此程序来计算用户下一个生日的天数,但是我收到了一个"找不到符号"当我尝试在我的最终方法中调用我的变量absolutepday,absolutebday,absolutepmonth和absolutbmonth时出错。我知道这个错误涉及范围,但对于我的生活,我无法弄清楚如何解决这个错误。

我已阅读此编译错误的其他帖子,但我仍然无法弄明白。

如果有人能够简单地告诉我如何解决这个问题并解释为什么会发生这种情况,我将不胜感激。

这是我的代码:



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.");
    }
}
&#13;
&#13;
&#13;

谢谢!

0 个答案:

没有答案