Skip to content

Instantly share code, notes, and snippets.

@PandyYang
Created May 5, 2018 08:44
Show Gist options
  • Save PandyYang/e3c5dd30aa99f65965167e780a5bd5fd to your computer and use it in GitHub Desktop.
Save PandyYang/e3c5dd30aa99f65965167e780a5bd5fd to your computer and use it in GitHub Desktop.
package justdo;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Scanner;
/**
* @author Pandy
* @date 2018/5/5 16:05
*/
public class GoodsManager2 {
public static void main(String[] args) {
ArrayList<Goods>list = new ArrayList<Goods>();
addGoods(list);
while(true){
int choose = chooseFunction();
switch (choose){
case 1:
printStore(list);
break;
case 2:
update(list);
break;
case 3:
exit();
return;
default:
System.out.println("===========");
System.out.println("请输入正确的序号!");
break;
}
}
}
public static void printStore(ArrayList<Goods> list){
int totalCount = 0;
double totalMoney = 0;
System.out.println("--------------------查看库存-------------");
System.out.println("品牌"+" " +"尺寸" +" "+"价格"+" "+"数量");
for (int i = 0;i<list.size();i++){
Goods item = list.get(i);
System.out.println(item.brand+" " +item.size + " " + item.price+" "+item.count);
totalCount += item.count;
totalMoney += item.price;
}
System.out.println("总的库存是:"+totalCount);
System.out.println("总的金额是:"+totalMoney);
}
public static void update(ArrayList<Goods> list) {
System.out.println("======修改库存数量==========");
for (int i = 0;i<list.size();i++){
Goods item = list.get(i);
System.out.println("请输入" + item.brand + "商品库存");
item.count = new Scanner(System.in).nextInt();
list.set(i,item);
}
}
public static void exit(){
System.out.println("====================退出====================");
System.out.println("您已经退出系统!");
}
public static void addGoods(ArrayList<Goods>list){
Goods g1 = new Goods();
Goods g2 = new Goods();
g1.brand = "ThinkPad";
g1.size = 5.99;
g1.price = 9999;
g1.count = 10;
g2.brand = "Apple";
g2.size = 6.00;
g2.price = 8888;
g2.count = 1;
list.add(g1);
list.add(g2);
}
public static int chooseFunction(){
System.out.println("====================库存管理=================");
System.out.println("1.查看库存清单");
System.out.println("2.修改商品库存的数量");
System.out.println("3.退出");
System.out.println("请输入要执行的序列号");
Scanner in = new Scanner(System.in);
int choose = in.nextInt();
return choose;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment