Closed. This question needs details or clarity。它当前不接受答案。
想改善这个问题吗?添加详细信息并通过editing this post阐明问题。
4年前关闭。
错误:WaterHeater类中的构造方法WaterHeater无法应用于给定类型。
必填:double,double,double,double,double
找到:没有参数
原因:实际和正式论据清单的长度不同
附加指针
将驼峰/小写与私有属性(而不是公共属性)一起使用
应该
使用Accessors and Mutators。
应该
主班也应该是这样
想改善这个问题吗?添加详细信息并通过editing this post阐明问题。
4年前关闭。
public class WaterHeater{
public double Kilowatts;
public double Water;
public double Joules;
public double Temp;
public double Jkg;
public double Energy;
public double Time;
//Constructor method
public WaterHeater (double Water, double Kilowatts, double Joules, double Temp, double Jkg) {
this.Water = Water;
this.Kilowatts = Kilowatts;
this.Joules = Joules;
this.Temp = Temp;
this.Jkg = Jkg;
}
//Accessor for Kilowatts
public double Kilowatts(){
return Kilowatts;
}
//Accessor for Water
public double Water(){
return Water;
}
//Method for Energy used
public double Energy(){
Energy = Water*Jkg*Temp;
return Energy;
}
//Method for Time to boil
public double Time(){
Time = Energy/Kilowatts;
return Time;
}
}
//Test class
public class Kettle extends WaterHeater{
public static void main( String args[] )
{
WaterHeater Kettle = new WaterHeater(1, 2, 3600, 70, 4200);
System.out.println("\nWater: " +Kettle.Water + " L" +
"\nKilowatts: " + Kettle.Kilowatts + " KW"+
"\nEnergy used: " +Kettle.Energy() + " J" +
"\nTime to boil: " +Kettle.Time() + " Seconds");
}
}
错误:WaterHeater类中的构造方法WaterHeater无法应用于给定类型。
必填:double,double,double,double,double
找到:没有参数
原因:实际和正式论据清单的长度不同
最佳答案
代码有很多约定,但是您尝试运行的代码存在问题,这是需要将其添加到Kettle类中
public Kettle(double Water, double Kilowatts, double Joules, double Temp, double Jkg) {
super(Water, Kilowatts, Joules, Temp, Jkg);
}
附加指针
将驼峰/小写与私有属性(而不是公共属性)一起使用
public double Kilowatts;
public double Water;
public double Joules;
public double Temp;
public double Jkg;
public double Energy;
public double Time;
应该
private double kilowatts;
private double water;
private double joules;
private double temp;
private double jkg;
private double energy;
private double time;
使用Accessors and Mutators。
public double Kilowatts() {
return Kilowatts;
}
应该
public double getKilowatts() {
return kilowatts;
}
public void setKilowatts(final String kilowatts) {
this.kilowatts = kilowatts;
}
主班也应该是这样
public class Kettle extends WaterHeater {
public Kettle(double water, double kilowatts, double joules, double temp, double jkg) {
super(water, kilowatts, joules, temp, jkg);
}
public static void main(String args[]) {
WaterHeater kettle = new WaterHeater(1, 2, 3600, 70, 4200);
System.out.println("\nWater: " + kettle.getWater() + " L" + "\nKilowatts: " + kettle.getKilowatts() + " KW" + "\nEnergy used: " + kettle.getEnergy() + " J"
+ "\nTime to boil: " + kettle.getTime() + " Seconds");
}
}