我已經正式走到了我的繩索的盡頭。我找不到我做錯了什麼。我已經完成了這個程序幾乎完全像我前幾天寫的另一個程序,但我編譯時遇到問題。我不知道爲什麼我在輸出線上出現錯誤。請幫助:多個班級:我在這裏做錯了什麼?
這是RUNNING FILE:
package inventory1;
import java.util.Scanner;
public class RunApp {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
DataCollection theProduct = new DataCollection();
String Name = "";
double pNumber = 0.0;
double Units = 0.0;
double Price = 0.0;
while (true) {
System.out.print("Enter Product Name: ");
Name = input.next();
theProduct.setName(Name);
if (Name.equalsIgnoreCase("stop")) {
return;}
System.out.print("Enter Product Number: ");
pNumber = input.nextDouble();
theProduct.setpNumber(pNumber);
System.out.print("Enter How Many Units in Stock: ");
Units = input.nextDouble();
theProduct.setUnits(Units);
System.out.print("Enter Price Per Unit: ");
Price = input.nextDouble();
theProduct.setPrice(Price);
System.out.print("\n Product Name: " + theProduct.getName());
System.out.print("\n Product Number: " + theProduct.getpNumber());
System.out.print("\n Amount of Units in Stock: " + theProduct.getUnits());
System.out.print("\n Price per Unit: " + theProduct.getPrice() + "\n\n");
System.out.printf("\n Total cost for %s in stock: $%.2f\n\n\n", theProduct.getName(), theProduct.calculatePrice());
}
}
}
這是數據集合文件:
package inventory1;
public class DataCollection {
String productName;
double productNumber, unitsInStock, unitPrice, totalPrice;
public DataCollection() {
productName = "";
productNumber = 0.0;
unitsInStock = 0.0;
unitPrice = 0.0;
}
// setter methods
public void setName(String name) {
productName = name;
}
public void setpNumber(double pNumber) {
productNumber = pNumber;
}
public void setUnits(double units) {
unitsInStock = units;
}
public void setPrice(double price) {
unitPrice = price;
}
// getter methods
public void getName(String name) {
productName = name;
}
public void getpNumber(double pNumber) {
productNumber = pNumber;
}
public void getUnits(double units) {
unitsInStock = units;
}
public void getPrice(double price) {
unitPrice = price;
}
public double calculatePrice() {
return (unitsInStock * unitPrice);
}
}
1)請格式化你的代碼妥善2)你得到什麼錯誤? – Zulan 2011-02-26 05:45:36
與佐蘭一樣......沒有格式良好的代碼和更多信息,很難提供幫助。 – Endophage 2011-02-26 05:47:46
我格式化他的代碼,長自動縮進! – 2011-02-26 05:55:36