可能重複:
I get an error when I try to compile my java code below: not sure for it to compile can anyone help? I don't understand the int in the error message.我不明白的INT錯誤消息
當我嘗試下面編譯我的Java代碼,我仍然收到此錯誤信息:
//作者:Donna Gary //日期:2011年4月10日 //等級:IT/215第五週庫存計劃1
import java.text.NumberFormat; import java.util.Locale; import java.util.Scanner;
類電視{
private String itemNumber;
private String productName;
private double units;
private double unitPrice;
private double unitsTotal;
//constructor
public Television (String itemNumber, String productName, double units, double unitprice, double unitsTotal) {
setItemNumber(itemNumber);
setProductName(productName);
setUnits(units);
setUnitPrice(unitPrice);
unitsTotal = units ++;
}
//accessor methods for class variables
public String getItemNumber() {
return itemNumber;
}
public void setItemNumber (String itemNumber) {
this.itemNumber = itemNumber;
}
public String getProductName() {
return productName;
}
public void setProductName (String productName) {
this.productName = productName;
}
public double getUnits() {
return units;
}
public void setUnits (double units) {
this.units = units;
}
public double getUnitPrice() {
return unitPrice;
}
public void setUnitPrice (double unitPrice) {
this.unitPrice = units * unitPrice;
}
public double getUnitsTotal() {
return unitsTotal;
}
public void setUnitsTotal (double unitsTotal) {
this.unitsTotal = units ++;
}
} 公共類InventoryPart1 {
public static void main (String args[]) {
int units;
double unitPrice;
double unitsTotal;
unitsTotal = units ++;
double unitsPrice;
unitsPrice = units * unitPrice;
double unitsTotalPrice;
unitsTotalPrice = unitsTotal * unitPrice;
double totalInventory;
totalInventory = unitsTotal * unitsTotalPrice;
NumberFormat nf = NumberFormat. getCurrencyInstance(Locale.US);
//create an instance of the Television class
Television samsung = new Television ("SAMSUNG 46 6400 Series」,」 Samsung Smart TV」, 「UN46D6400UF");
//use the methods from class Television to output the inventory details.
System.out.println("Item Number: " + samsung.getItemNumber());
System.out.println("Product Name: " + samsung.getProductName());
System.out.print("Number of Units: ");
System.out.println(nf.format(units));
System.out.print("Unit Price: ");
System.out.println(nf.format(unitPrice));
System.out.print("Units Total: ");
System.out.println(nf.format(unitsTotal));
System.out.print("Units Total Price: ");
System.out.println(nf.format(unitsTotalPrice));
System.out.print("Total Inventory: ");
System.out.println(nf.format(totalInventory));
}
}
我不明白錯誤消息的int
。 。
C:\\Documents and Settings\AdminUser\My Documents\InventoryPart1.java:96:
cannot find symbol symbol : constructor Television(java.lang.String)
location: class Television
Television samsung = new Television("SAMSUNG 46 6400 Series","Samsung SmartTV", "UN46D6400UF");
^1 error Tool completed with exit code 1
你能發佈你的代碼嗎?沒有它,很難知道發生了什麼。 – juanchopanza 2011-04-11 17:20:00
代碼?或者添加一個與Television(String name)相匹配的構造函數。 – 2011-04-11 17:20:05
什麼是int?你是在談論.java之後的96,還是退出代碼1? – 2011-04-11 17:20:15