
| 任务 | 姓名 |
|---|---|
| 编码规范、前期调查与功能设计 | 赵洋 |
| 面向对象设计、PPT制作或博客制作 | 郭少池 |
系统功能结构图
系统描述:显示菜单,添加,删除或修改商品到商场中,判断是否符合条件,符合进行修改,不符合则返回菜单。显示菜单,添加,删除或修改商品到购物车中,判断是否符合条件,符合进行修改,不符合则返回菜单。
本系统哪里体现了面向对象的封装性。可选:哪里体现了继承与多态。
每个类中的属性以及方法都体现了面向对象的封装性
由UML类图可看出类与类之间体现了继承和多态
项目包结构与关键代码: 项目的包结构分为product,ShoopingCenter,productInf,ShoopingCenter,Main。
这样设计包结构可以体现面向对象的设计的流程图与关键代码。
添加public void add(){
while (true) {
Scanner sc = new Scanner(System.in);
String name=sc.next();
int number=sc.nextInt();
Double price=sc.nextDouble();
if ("end".equals(name)) {
break;
}
Product pro = new Product(name,number, price);
List.add(pro);
}
}
public void add(List删除List) {//添加 System.out.println("请输入您要买的商品名称:"); Scanner sc = new Scanner(System.in); String name = sc.next(); for (Product p : List) { if (p.getproductName().equals(name)) { System.out.println("您要买的商品单价为:" + p.getPrice() + "元"); System.out.println("请输入您要买的件数:"); int t = sc.nextInt(); BigDecimal count = new BigDecimal(t + ""); BigDecimal price = new BigDecimal(p.getPrice() + ""); Sum = count.multiply(price); // System.out.println("合计:"+Add+"元"); Cart.add(p); return; } } System.out.println("无该商品,请重新输入"); }
public void delCart(List总计Cart) { System.out.println("请输入你要删除的商品:"); Scanner sc = new Scanner(System.in); String name1 = sc.next(); for (Product p : Cart) { if (p.getproductName().equals(name1)) { Cart.remove(p); } } }
public class ShoppingCart {
private BigDecimal Sum = new BigDecimal(0);
public void showCart() {
for (ProductInf p : Cart) {
System.out.println(p);
}
System.out.println("合计:" + Sum + "元");
}
判断
public int HaveCommodity(int no) {//判断商场中有没有该商品
int i=0;
for( i=0;i
结束