import java.util.Scanner;
/**
* @author :jiliangliang
* @description:PACKAGE_NAME ShopApp
* @date :2022/6/11 14:16
*/
public class ShopApp {
public static void main(String[] args) {
Double allprice = 0.0;
while (true){
Scanner scanner = new Scanner(System.in);
System.out.println("请输入名称");
String name = scanner.nextLine();
System.out.println("请输入数量");
String quantity= scanner.nextLine();
System.out.println("请输入单价");
String unitPrice = scanner.nextLine();
Item item = new Item(name,Double.parseDouble(quantity),Double.parseDouble(unitPrice));
System.out.println(item.name+":"+item.getAmount());
allprice += item.getAmount();
System.out.println("总价:"+allprice);
}
// Item item = new Item("苹果",3.2,4.8);
// System.out.println(item.name+":"+item.getAmount());
// Item item2 = new Item("香蕉",2.1,2.8);
// System.out.println(item2.name+":"+item2.getAmount());
// Item item3 = new Item("火龙果",1.2,3.5);
// System.out.println(item3.name+":"+item3.getAmount());
}
}
class Item {
public String name;
public Double quantity;
public Double unitPrice;
public Item(String name,Double quantity,Double unitPrice){
this.name = name;
this.quantity = quantity;
this.unitPrice= unitPrice;
}
public Double getAmount(){
return this.unitPrice*this.quantity;
}
}
最后修改:2022 年 06 月 15 日
© 允许规范转载