当前位置:   article > 正文

java基础案例6-1库存管理系统_java库存管理系统案例

java库存管理系统案例
  1. package com.itheima;
  2. import java.util.*;
  3. import static java.lang.System.exit;
  4. public class Main{
  5. static Scanner in = new Scanner(System.in);
  6. static LinkedList link = new LinkedList();
  7. public static void main(String[] args)
  8. {
  9. while(true) {
  10. menu();
  11. input();
  12. }
  13. }
  14. static void menu()
  15. {
  16. System.out.println("--------------库存管理系统--------------");
  17. System.out.println("(1)商品入库 (2)商品显示功能");
  18. System.out.println("(3)删除商品 (4)退出");
  19. }
  20. static void input()
  21. {
  22. System.out.print("请输入需要的操作:");
  23. int choose = in.nextInt();
  24. switch(choose)
  25. {
  26. case 1: infood();break;
  27. case 2: showfood();break;
  28. case 3: delfood(); break;
  29. case 4: exit(0);
  30. }
  31. }
  32. static void infood(){
  33. while(true)
  34. {
  35. System.out.print("是否要录入商品(是输入1/否输入0):");
  36. int d = in.nextInt();
  37. if(d == 1) {
  38. String[] a = new String[4];
  39. String ch;
  40. System.out.print("请输入商品的名称:");
  41. a[0] = in.next();
  42. System.out.print("请输入商品的颜色:");
  43. a[1] = in.next();
  44. System.out.print("请输入商品的价格:");
  45. a[2] = in.next();
  46. System.out.print("请输入商品的数量:");
  47. a[3] = in.next();
  48. ch = "名称:" + a[0] + " 颜色:" + a[1] + " 价格:" + a[2] + " 数量:" + a[3];
  49. link.add(ch);
  50. System.out.println("商品录入成功");
  51. showfood();
  52. }
  53. else
  54. return;
  55. }
  56. }
  57. static void showfood(){
  58. if(link.isEmpty())
  59. {
  60. System.out.println("库房没有商品");
  61. return;
  62. }
  63. System.out.println("所有商品如下:");
  64. int j = 0;
  65. for(Object str : link)
  66. {
  67. System.out.print("编号(" + ++j + "): " );
  68. System.out.println(str);
  69. }
  70. }
  71. static void delfood(){
  72. while(true) {
  73. System.out.print("请输入需要删除的商品编号(输入0退出):");
  74. int num = in.nextInt();
  75. if(num == 0)
  76. break;
  77. link.remove(num - 1);
  78. }
  79. showfood();
  80. }
  81. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Guff_9hys/article/detail/877395
推荐阅读
相关标签
  

闽ICP备14008679号