1 回答
TA贡献1818条经验 获得超7个赞
你可以使用 你可以使用 不清楚你不能做什么。List<String>String s =id+" | " + name + " | " + quantity + " | " + amount
但是,如果需要,您可以创建对象,并将其命名为...菜单。
public class Menu {
private int productId;
private int quantity;
private int price;
private int totalPrice;
private String productName;
public Menu(){}
public Menu(int productId,int quantity,int price,int totalPrice,String productName){
this.productId=productId;
this.quantity=quantity;
this.price=price;
this.totalPrice=totalPrice;
this.productName=productName;
}
//setters and getters
public void setProductId(int productId) {
this.productId = productId;
}
public int getProductId() {
return productId;
}
public void setProductName(int productName) {
this.productName= productName;
}
public int getProductName() {
return productName;
}
public int getQuantity() {
return quantity;
}
public void setQuantity(int quantity) {
this.quantity = quantity;
}
public int getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public int getTotalPrice() {
return totalPrice;
}
public void setTotalPrice(double totalPrice) {
this.totalPrice = totalPrice;
}
}
在你当前的课程中,你可以做一些类似的东西
Menu menu=new Menu();
System.out.print("Select ID Number: ");
menu.setProductId(id.nextInt());
System.out.println("Input quantity: ");
menu.setQuantity(id.nextInt());
System.out.println("Quantity: "+menu.getQuantity());
menu.setProductName(products[menu.getProductId()])
System.out.println("Product Name: "+menu.getProductName());
menu.setPrice(prices[menu.getProduct(id)]);
menu.setTotalPrice(menu.getPrice()*menu.getQuantity());
System.out.println("Amount to be Paid: "+menu.getTotatPrice());
添加回答
举报