我正在尝试创建销售菜单,但我正在努力奋斗。所以这是我的产品类:
import java.text.*;
public class Product {
private String name;
private int stock;
private double price;
public Product(String name, int stock, double price) {
String[] itemName = {"Whiteboard Marker, Whiteboard Eraser, Black Pen, Red Pen, Blue Pen"};
double[] itemPrice = {1.50, 5.00, 1.50, 1.50, 1.50};
int[] itemStock = {85, 45, 100, 100, 100};
}
public String getName() {
return "";
}
public boolean isEmpty() {
return false;
}
/**
* Return true iff this product has at least n stock
*/
public boolean has(int n) {
return true;
}
/**
* Sell n stock of this product (decrease stock by n)
* and return the amount of money earned (price * n)
*/
public double sell(int n) {
return 0.0;
}
/**
* Increase stock by n.
*/
public void restock(int n) {
}
@Override
public String toString() {
return name + " - " + stock + " at $" + formatted(price);
}
private String formatted(double money) {
return new DecimalFormat("###,##0.00").format(money);
}
}
然后我又开了一个班:
import java.util.*;
public class Store {
private CashRegister cashRegister;
private LinkedList<Product> products = new LinkedList<Product>();
public Store() {
products.add(new Product("Whiteboard Marker"));
products.add(new Product("Whiteboard Eraser"));
products.add(new Product("Black Pen"));
products.add(new Product("Red Pen"));
products.add(new Product("Blue Pen"));
}
private char readChoice() {
return 'x';
}
private void sell() {
}
private void restock() {
}
private void viewStock() {
}
private void viewCash() {
}
private void pruneProducts() {
}
private String readName() {
return "No Name";
}
private double readPrice() {
return 0.0;
}
private int readNumber() {
return 0;
}
private void help() {
System.out.println("Menu options");
System.out.println("s = sell");
System.out.println("r = restock");
System.out.println("v = view stock");
System.out.println("c = view cash");
System.out.println("p = prune products");
System.out.println("x = exit");
}
}
但是当我试图编译它时,#34;构造函数Product in Class Product不能应用于给定的类型; required:java.lang.String,int,double;发现:java.lang.String;原因:实际和正式的参数列表长度不同。&#34; 如果您对此有任何疑问,请向我解释。非常感谢你!