我已经研究了解决方案,并且一直在研究这个年龄,除了我在编译过程中不断收到这两个错误,特别是变量可能没有被初始化?我已经在两个类之间交替使用解决方案,但它是类似的错误。
我的问题是:我该如何解决以下错误[谢谢]。.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);
代码中的这一行阻止我成功编译。我在下面标出了两行[第 129 行]和[第 130 行]。
**[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.");
为了您的方便,我还包括了两套完整的类,分别在下面的 App 类和 Leap 类。
类应用程序已编辑。
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);
}
}