gpt4 book ai didi

库存程序的 Java 代码第 3 部分无法编译

转载 作者:行者123 更新时间:2023-12-02 08:19:44 24 4
gpt4 key购买 nike

已更正之前的错误,现在出现此错误。

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

最佳答案

所以有两个错误。第一个出现在文件 InventoryPart3.java 的第 93 行。在该行上您将找到代码:

 super(ItemNumber, ProductName, UnitsStock, UnitPrice);

这实际上是对电视类的构造函数的调用。但是,电视类的构造函数接受 5 个参数:String、String、double、double、String,但您只传递了 4 个。

第二个错误发生在同一文件的第 120 行。在这种情况下,您似乎正在调用一个方法,但省略了括号。也就是说,代码应该是:

   getInventoryValue()

关于库存程序的 Java 代码第 3 部分无法编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5711276/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com