我有2個錯誤消息,我無法弄清楚它是什麼問我。的錯誤是:Java庫存程序問題
Desktop\Inventory Program\InventoryPart1.java:93: cannot find symbol symbol : variable printer location: class InventoryPart1 System.out.println("Item Number: " + printer.getItemNumber()); Desktop\Inventory Program\InventoryPart1.java:95: cannot find symbol symbol : variable printer`enter code here` location: class InventoryPart1 System.out.println("Product Name: " + printer.getProductName());
到目前爲止的代碼是
import java.text.NumberFormat; import java.util.locale; import java.util.Scanner; class Printer { private String itemNumber; private String productName; private double units; private double unitPrice; private double unitsTotal; //constructor public Printer (String itemNumber, String productName, double units, 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 ++; } } public class 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 Printer class Printer epson = new Printer ("Epson579", "All In One", 2, 50.99); //use the methods from class Printer to output the inventory details. System.out.println("Item Number: " + printer.getItemNumber()); System.out.println("Product Name: " + printer.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)); } }
對不起新來這個網站,並仍在試圖搞清楚這些事情與整個代碼進入,
這一切都很好!我爲你格式化了代碼,所以不用擔心。 :) – fireshadow52