admin管理员组

文章数量:1566223

2024年3月31日发(作者:)

public class MainTest {

/**

* 啤酒 3.5元/每罐,方便面 4.5/每包,矿泉水 2.0/每瓶

*小美购买商品:啤酒 3罐,方便面3包,矿泉水2瓶

*小明购买商品:啤酒2罐,方便面5包

*

* @param args

*/

public static void main(String[] args) {

Listproducts = new ArrayList();

//小美购买商品列表

Product beer = new Product("beer", 3.5f, 3);

Product instantNoodle = new Product("instance noodle", 4.5f, ;

Product water = new Product("water", 2.0f, 2);

(beer);

(instantNoodle);

(water);

float totalPrice = 0.0f;

for (Products product : products) {

totalPrice += nt();

}

totalPrice = (float)(totalPrice*100)/100;

n("小美购买商品的总价:" + totalPrice);

//小明购买商品的总价

Product beer2 = new Product("beer", 3.5f, 2);

Product instantNoodle2 = new Product("instance noodle", 4.5f, 5);

();

(beer2);

(instantNoodle2);

float totalPrice2 = 0.0f;

for (Product product : products) {

totalPrice2 += nt();

}

totalPrice2 = (float)(totalPrice2*100)/100;

n("小明购买商品的总价:" + totalPrice2);

}

}

本文标签: 购买商品形考任务程序设计