Leap不能应用于使用Java编译测试

Leap不能应用于使用Java编译测试,java,Java,我一直在研究解决方案,并一直致力于这方面的工作,直到目前为止,除了在编译过程中不断出现这两个错误,特别是变量可能尚未初始化?我已经在两个类之间交替使用了解决方案,但这是类似的错误 我的问题是:我如何解决以下错误[谢谢]。调用setIsLeapYear()但不带参数,而在Leap类中使用一个参数定义 App.java:129: setisLeapYear(int) in Leap cannot be applied to () aLeap.setisLeapYear(); //aL

我一直在研究解决方案,并一直致力于这方面的工作,直到目前为止,除了在编译过程中不断出现这两个错误,特别是变量可能尚未初始化?我已经在两个类之间交替使用了解决方案,但这是类似的错误

我的问题是:我如何解决以下错误[谢谢]。调用setIsLeapYear()但不带参数,而在Leap类中使用一个参数定义

App.java:129: setisLeapYear(int) in Leap cannot be applied to ()
        aLeap.setisLeapYear(); //aLeap.setisLeapYear(anLeapYear);
             ^
App.java:130: setisNotLeapYear(int) in Leap cannot be applied to ()
        aLeap.setisNotLeapYear(); //aLeap.setisNotLeapYear(anNotLeapYear);
代码中的这一行阻止我成功编译。我划出了两行,如下所示

    **[line 129]** aLeap.setisLeapYear(); //aLeap.setisLeapYear(anLeapYear);
    **[line 130]** aLeap.setisNotLeapYear(); //aLeap.setisNotLeapYear(anNotLeapYear);
    aLeap.sortLeapyear();

    //year=aYear.sortLeapyear();

    oBox.show();
    oBox.print("The " + anLeapYear + " is a leap year."); //leap.anLeapYear //aLeap.anLeapYear //aLeap.isLeapYear
    //"The " + year + " is a leap year.")
    //"The " + year + " is a leap year: " + isLeapYear);
    //System.out.println("This is a leap year!" + isLeapYear);

    oBox.print("The " + anNotLeapYear + " is not a leap year."); 
我还包括两个完整的类,分别为你的便利应用程序类和飞跃类下面

类应用程序已编辑

import javabook.*;

class App
{

public static void main(String args[])
{
    App thisProgram = new App();   



}   
    //outside a main class
    public App()
    {

        //contsructor
        //set variables
        //int aYear = 2000; //year
        int aYear = 2000; EDITED.
        int anLeapYear;
        int anNotLeapYear;

        //declare objects
        MainWindow mWindow;
        Leap aLeap;
        InputBox iBox;
        OutputBox oBox;

        //create objects                
        mWindow = new MainWindow();     
        aLeap = new Leap();
        iBox = new InputBox(mWindow);   
        oBox = new OutputBox(mWindow);  

        mWindow.show();

        //get input of base and height
        aYear = iBox.getInteger("Enter a year: "); //aYear

        int year = aLeap.getisLeapYear();//

        boolean value = true; 
        if (value == true)


        aLeap.setisLeapYear(); //aLeap.setisLeapYear(anLeapYear);
        aLeap.setisNotLeapYear(); //aLeap.setisNotLeapYear(anNotLeapYear);
        aLeap.sortLeapyear();

        //year=aYear.sortLeapyear();

        oBox.show();
        oBox.print("The " + anLeapYear + " is a leap year."); 
        oBox.print("The " + anNotLeapYear + " is not a leap year."); 
        //the end.
    }
}.
班级飞跃

class Leap
{
    //public static void main(String args[])

    //data
    //private constants
    final int year; 

    //private variables
    private int isLeapYear;
    private int isNotLeapYear;

    //constructors //Leapyear
    public Leap()
    {
        //this.isLeapYear = 0;      
        //this.isNotLeapYear = 0;   
    }
    //methods - behavious
    public void sortLeapyear() 
    {   
        boolean value = true; 
        if (value == true) 

        if (year % 4 == 0) //((year % 4) == 0) 
        {
        if (year % 100 == 0) 
            {
            if (year % 400 != 0)
            {
            }
            if (year % 400 == 0)
            {
            }
    }
        if (year % 100!= 0)
            {
            }
        }
        if (year % 4 != 0)
            {
            }

        //this.isLeapYear = ( ((year % 400) == 0) || ((year % 4) == 0 && (year % 100) != 0)  ); SHOULD BE IN IF STATEMENT ON LEAP YEAR.
        //this.isLeapYear = ((year % 4 == 0) && (year % 100 == 0) && (year % 400 == 0));
        //(year % 400 == 0) && (year % 100 != 0) || (year % 4 == 0); //http://ubuntuforums.org/archive/index.php/t-1264964.html
        //http://en.wikiversity.org/wiki/Introduction_to_Programming_in_Java/Boolean_variables
        //this.isLeapYear = ((year % 4) == 0); //(year % 400 == 0);
        //this.isLeapYear = (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);  //found   : boolean   //1 + (int) (Math.random() * NUMBER_OF_SIDES);
        //this.isLeapYear = ((year % 4 == 0) && (year % 100 == 0) && (year % 400 == 0));//1 + (int) (Math.random() * NUMBER_OF_SIDES);
}

        //Set the height and get the height
        public void setisLeapYear(int anLeapYear)
        {
            this.isLeapYear = year;
        }
        //method - Get (accessors) and sets (mutators)
        public int getisLeapYear()
        {
            return(this.isLeapYear);
        }

        public void setisNotLeapYear(int isNotLeapYear)
        {
            this.isNotLeapYear = year;
        }
        //method - Get (accessors) and sets (mutators)
        public int getisNotLeapYear()
        {
            return(this.isNotLeapYear);
        }
}

您的问题是,您有
setisLeapYear
方法获取
一个参数
,当您调用它时,您不会向该方法发送任何内容

解决方案是:
您可以创建不带任何内容的
setisLeapYear
,如下所示:

 public void setisLeapYear(////nothing here)
 {
...

 }
aLeap.setisLeapYear(///put number here );

int
发送到您称之为
anLeapYear
的方法,如下所示:

 public void setisLeapYear(////nothing here)
 {
...

 }
aLeap.setisLeapYear(///put number here );

这里的问题是什么?您没有按定义调用该方法。如果你想调用一个无参数的方法,请定义这样一个方法。我想说错误很明显,你调用了
setisLeapYear()
,这是没有定义的。我在App类和leap类中有一些变量没有在oBox.print中读取(“the”+anLeapYear+“是闰年”);很明显,我设置的变量不正确。setIsLeapYear()被调用,但没有参数,而它是在Leap类中用一个参数定义的。setIsLeapYear()没有定义,我如何解决这个问题?stack_用户:您在
Leap
类中定义
setIsLeapYear()
aLeap.setIsLeapYear(///将数字放在这里);那是哪个号码?我得到int-aYear=2000;关于集合变量。是数字2000应该放在(///put number here)这个
setisLeapYear
方法中取一个数字,所以你必须将数字发送给它,否则编译器会将此方法作为另一个方法处理,但不是defineyes,我可以看到,
anLeapYear
的值在哪里??您需要初始化它Yes:)将值设置为此变量:)就像您在中所做的那样:
int aYear=2000
在这里创建int变量,并在2000年前初始化它,如果需要,可以通过代码更改此值,
int anLeapYear=///但是这里的值,我只是试着向您解释如何做,但您需要更多的学习:)