纠正了以前的错误,现在出现了这个错误。
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发布于 2011-04-19 03:32:59
所以有两个错误。第一个出现在文件InventoryPart3.java的第93行。在这一行中,您将找到代码:
super(ItemNumber, ProductName, UnitsStock, UnitPrice);这实际上是对电视类的构造函数的调用。然而,the类的构造函数接受5个参数: String、String、double、double、String,但您只传递了4个参数。
第二个错误发生在同一文件的第120行。在这种情况下,您似乎在调用一个方法,但是省略了括号。也就是说,守则应是:
getInventoryValue()发布于 2011-04-19 03:33:35
在电视类中,您试图从制造商类调用的超级电视的构造函数并不存在。请查看超级()调用中的参数和the构造函数中的实际参数。getInventoryValue函数不在an class.Hence中,它正在为super.getInventory调用抛出一个错误
发布于 2011-04-19 03:33:51
第一个错误与to构造函数有关。电视构造函数采用5个参数,类型为String、String、double、double、String。在制造商类中,使用int、string、int和double调用超类构造函数。在子类中,超级()构造函数调用必须匹配基类( the )中的一个构造函数。
对于第二个错误,对getInventoryValue的调用有一个语法错误。要在Java中调用方法,必须在方法的名称后面加上括号:
return super.getInventoryValue() * 0.10;注意,在本例中,super.部分是可选的。getInventoryMethod()存在于超类中,不属于私有类,因此可以从子类中调用它,如下所示:
return getInventoryValue() * 0.10;https://stackoverflow.com/questions/5711276
复制相似问题