对以前的错误进行了修正,现在出现了这个错误。
C:\Documents and Settings\AdminUser\My Documents\InventoryPart3.java:93: invalid method declaration; return type required
public Television(int ItemNumber, String ProductName, int UnitsStock, double UnitPrice, String mfgName) {
^
1 error
Tool completed with exit code 1
class Television { //class name and attributes
private String ItemNumber; //item # of product
private String ProductName; //product name
private double UnitsStock; //# of units in stock
private double UnitPrice; //Price per unit
private String SerialNumber; //serial number of product
private double InventoryValue; //The dollar value of the inventory in stock
//constructor
public Television (String item, String product, double units, double price, String serial) {
ItemNumber = item;
ProductName = product;
UnitsStock = units;
UnitPrice = price;
SerialNumber = serial;
} //end constructor
///getter and setter methods for Television
public void setItemNumber (String item) { //setter for item number
this.ItemNumber = item;
} //end setter item number
public String getItemNumber() { //getter for item number
return ItemNumber;
} //end getter item number
public void setProductName (String product) { //setter for product name
this.ProductName = product;
} //end setter product name
public String getProductName() { //getter for product name
return ProductName;
} //end getter product name
public void setUnitsStock (double units) { //setter for units in stock
this.UnitsStock = units;
} //end setter units in stock
public double getUnitsStock() { //getter for units in stock
return UnitsStock;
} //end getter units in stock
public void setUnitPrice (double price) { //setter for unit price
this.UnitPrice = price;
} //end setter unit price
public double getUnitPrice() { //getter for unit price
return UnitPrice;
} //end getter for unit price
public void setSerialNumber (String serial) { //setter for serial number
this.SerialNumber = serial;
}//end setter for serial number
public String getSerialNumber() { //getter for serial number
return SerialNumber;
}//end getter for serial number
//calculate individual product inventory value
public double getInventoryValue(){
return UnitsStock * UnitPrice;
}//end calculate individual product inventory value
//calculate total inventory value
public double calculateInventory(){
return UnitPrice * UnitsStock;
}//end calculate total inventory value
///end getter and setter methods for Laptop
} //end class Television
class Manufacturer extends Television {
private String manufacturerName;
//constructor
public Television(int ItemNumber, String ProductName, int UnitsStock, double UnitPrice, String mfgName) {
super(ItemNumber, ProductName, UnitsStock, UnitPrice, ManufacturerName);
this.manufacturerName = mfgName;
}//end constructor
//getter and setter for class Manufacturer
public void setmanufacturerName(String mfgName) {
this.manufacturerName = mfgName;
}
public String getmanufacturerName() {
return manufacturerName;
}
//end getter and setter for class Manufacturer
//calculate total inventory value
public double calculateInventory(){
return ((UnitPrice * UnitsStock));
}//end calculate total inventory value
//calculate restocking fee method
public double getcalculateRestockFee() {
return getInventoryValue();
}//end calculate restocking fee method
}//end class Manufacturer
答案 0 :(得分:2)
所以有两个错误。第一个发生在InventoryPart3.java文件的第93行。在那一行,你会找到代码:
super(ItemNumber, ProductName, UnitsStock, UnitPrice);
这实际上是对电视类构造函数的调用。但是,电视类的构造函数接受5个参数:String,String,double,double,String但是你只传递了4个。
第二个错误发生在同一文件的第120行。在这种情况下,您似乎在调用方法,但是您省略了括号。也就是说,代码应该是:
getInventoryValue()
答案 1 :(得分:0)
你试图从制造商类使用super调用的电视构造函数在电视课上不存在。请参阅super()调用中的参数以及Television构造函数中的实际参数。电视类中没有getInventoryValue函数。因为它为super.getInventory调用抛出错误
答案 2 :(得分:0)
第一个错误与您的电视构造函数有关。您的电视构造函数接受5个String,String,double,double,String类型的参数。在您的Manufacturer类中,您使用int,string,int和double调用超类构造函数。在子类中,您的super()构造函数调用必须与基类(电视)中的一个构造函数匹配。
对于第二个错误,您对getInventoryValue的调用存在语法错误。要在Java中调用方法,必须在方法名称后面添加括号:
return super.getInventoryValue() * 0.10;
请注意,在这种情况下,super.
部分是可选的。 getInventoryMethod()存在于超类中,并不是私有的,因此您可以从子类中调用它,如下所示:
return getInventoryValue() * 0.10;