这个问题不太可能帮助任何未来的游客;它只与一个小的地理区域、一个特定的时刻或一个非常狭窄的情况有关,而这些情况通常不适用于互联网的全球受众。有关使此问题更广泛适用的帮助,请访问帮助中心。
7年前关门了。
我一直在研究解决方案,并一直在这个时代的工作,取得了这么远的例外,我不断得到这两个错误在编译过程中,特别是变量可能没有初始化?我已经在两个类之间交替求解了,但都是类似的错误。
我的问题是:我如何解决这个错误如下[谢谢你]。调用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.");
我还包括两个完整的类,为您的方便应用程序类和飞跃类分别下面。
类应用程序已编辑。
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);
}
}
1条答案
按热度按时间pkwftd7m1#
你的问题是,你有
setisLeapYear
采取的方法one argument
当你调用它时,你不会给这个方法发送任何信息解决方案是:
您可以创建
setisLeapYear
什么也不拿,像这样:或者
发送
int
你称之为anLeapYear
,例如: