我已经为Inventory程序重新编写了我的java代码,但是我仍然无法获得编译代码.
import java.text.NumberFormat;
import java.util.Locale;
import java.util.Scanner;
class Television {
private String itemNumber;
private String productName;
private double units;
//constructor
public Television (String itemNumber, String productName, double units, double unitprice) {
setItemNumber(itemNumber);
setProductName(productName);
setUnits(units);
setUnitPrice(unitPrice);
}
//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 = unitPrice;
}
}
public class InventoryPart1 {
public static void main (String args[]) {
NumberFormat nf = NumberFormat. getCurrencyInstance(Locale.US);
//create an instance of the Television class
Television samsung = new Television ("SAMSUNG 46", "Class 6400 Series", 9.3,1,599.99);
//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: " + samsung.getUnits());
System.out.print("Unit Price: " + nf.format(Samsung.getUnitPrice()));
System.out.print("Inventory______ Total:_______"+
nf.format(samsung.calculateInventoryTotal());
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
C:\ Documents and Settings\AdminUser\MyDocuments\InventoryPart1.java:81:')'expected nf.formatsamsung.calculateInventoryTotal)); ^ 1错误工具已完成,退出代码为1
你错过了一个括号!
最后一行应该说:
System.out.print("Inventory______ Total:_______"+ nf.format(samsung.calculateInventoryTotal()));
Run Code Online (Sandbox Code Playgroud)
(最后添加了一个)字符)
祝好运!
事实上,这正是错误所说的:')' expected完全意味着 - 编译器期待一个)角色并且不存在!:)