发布于2020-11-19 20:36 阅读(842) 评论(0) 点赞(29) 收藏(5)
- import java.util.ArrayList;
- import java.util.Scanner;
-
- public class Fri_Demo {
-
-
- public static void main(String[] args) {
-
- ArrayList<FruitItem> list = new ArrayList<>();//所有商品的集合
-
- InitFriSystem();
-
- choose(list);
-
- }
-
- public static void InitFriSystem(){
-
- // - 3.1.库存货物查询
- // - 3.2.添加新货物
- // - 3.3.删除货物
- // - 3.4.修改货物
- // - 3.5.退出系统,结束main方法的运行
- System.out.println("======欢迎进入商品管理系统=======");
- System.out.println("======1.库存货物查询=======");
- System.out.println("======2.添加新货物=======");
- System.out.println("======3.删除货物=======");
- System.out.println("======4.修改货物=======");
- System.out.println("======5.退出系统=======");
-
- }
-
- public static void FruitItemSelect(ArrayList<FruitItem> list){
-
-
- for (int i=0;i<list.size();i++){
-
- FruitItem fruitItem = list.get(i); //货物对象
- // private int ID; //商品编号
- //
- // private String name; //商品名称
- //
- // private double price; //商品单价
- //
- // private double number; //商品数量
- //
- // private double money; //商品金额
- System.out.println("货物的商品编号"+fruitItem.getID()+"名称是:"+fruitItem.getName()+"单价是:"+fruitItem.getPrice()+"" +
- "数量是:"+fruitItem.getNumber()+"金额是:"+fruitItem.getMoney());
-
- }
-
- }
-
- public static void AddItems(ArrayList<FruitItem> list){
- Scanner scanner = new Scanner(System.in);//alt enter
- //默认每次添加一个商品进去
- FruitItem fruitItem = new FruitItem();
- System.out.println("请输入商品编号是:");
- int ID = scanner.nextInt();
- System.out.println("请输入商品名称是:");
- String name = scanner.next();
- System.out.println("请输入商品单价是:");
- double price = scanner.nextDouble();
- System.out.println("请输入商品数量是:");
- double number = scanner.nextDouble();
- System.out.println("请输入商品金额是:");
- double money = scanner.nextDouble();
-
- fruitItem.setID(ID);
- fruitItem.setName(name);
- fruitItem.setPrice(price);
- fruitItem.setNumber(number);
- fruitItem.setMoney(money);
-
-
- list.add(fruitItem);
-
- System.out.println("商品添加完成");
-
- }
-
- public static void DeleteItems(ArrayList<FruitItem> list){
- System.out.println("请输入你要删除的商品的编号是:");
-
- Scanner scanner = new Scanner(System.in);
-
- int ID = scanner.nextInt();
-
- //我们从键盘上读取到要删除的货物的ID 要去存储货物的list去查询ID当前输入的Id的这个货物对象
- for(int i=0;i<list.size();i++){
-
- if(list.get(i).getID()==ID){
-
- list.remove(i);
-
- }
-
- }
-
-
- }
-
- public static void UpdateItems(ArrayList<FruitItem> list){
-
- System.out.println("请输入你要修改的商品的编号是:");
-
- Scanner scanner = new Scanner(System.in);
-
- int ID = scanner.nextInt();
- System.out.println("请输入你要修改的商品名称是:");
- String name = scanner.next();
- System.out.println("请输入你要修改的商品单价是:");
- double price = scanner.nextDouble();
- System.out.println("请输入你要修改的商品数量是:");
- double number = scanner.nextDouble();
- System.out.println("请输入你要修改的商品金额是:");
- double money = scanner.nextDouble();
-
- FruitItem fruitItem = new FruitItem();
-
- fruitItem.setID(ID);
- fruitItem.setName(name);
- fruitItem.setPrice(price);
- fruitItem.setMoney(money);
- fruitItem.setNumber(number);
-
- for(int i=0;i<list.size();i++){
-
- if(list.get(i).getID()==ID){
-
- list.set(i,fruitItem);
- System.out.println("恭喜你修改成功了");
-
- }
-
- }
-
- }
-
- public static void choose(ArrayList<FruitItem> list){
-
- Scanner scanner = new Scanner(System.in);
-
- while (true){
-
- int choose = scanner.nextInt();
-
- switch (choose){
- case 1:
- //1.库存货物查询
- FruitItemSelect(list);
- break;
- case 2:
- //2.添加新货物
- AddItems(list);
- break;
- case 3:
- //3.删除货物
- DeleteItems(list);
- break;
-
- case 4:
- // 4.修改货物
- UpdateItems(list);
- break;
- case 5:
- System.exit(0);
- break;
- default:
-
- System.out.println("错误命令");
- return;
-
- }
-
- }
-
- }
- }
原文链接:https://blog.csdn.net/qq_28943665/article/details/109747925
作者:我爱java
链接:http://www.javaheidong.com/blog/article/892/561fa34201b2c08b168a/
来源:java黑洞网
任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任
昵称:
评论内容:(最多支持255个字符)
---无人问津也好,技不如人也罢,你都要试着安静下来,去做自己该做的事,而不是让内心的烦躁、焦虑,坏掉你本来就不多的热情和定力
Copyright © 2018-2021 java黑洞网 All Rights Reserved 版权所有,并保留所有权利。京ICP备18063182号-2
投诉与举报,广告合作请联系vgs_info@163.com或QQ3083709327
免责声明:网站文章均由用户上传,仅供读者学习交流使用,禁止用做商业用途。若文章涉及色情,反动,侵权等违法信息,请向我们举报,一经核实我们会立即删除!