赞
踩
- package com.itheima;
-
- import java.util.*;
-
- import static java.lang.System.exit;
-
- public class Main{
- static Scanner in = new Scanner(System.in);
- static LinkedList link = new LinkedList();
- public static void main(String[] args)
- {
- while(true) {
- menu();
- input();
- }
- }
-
- static void menu()
- {
- System.out.println("--------------库存管理系统--------------");
- System.out.println("(1)商品入库 (2)商品显示功能");
- System.out.println("(3)删除商品 (4)退出");
- }
-
- static void input()
- {
- System.out.print("请输入需要的操作:");
- int choose = in.nextInt();
- switch(choose)
- {
- case 1: infood();break;
- case 2: showfood();break;
- case 3: delfood(); break;
- case 4: exit(0);
- }
- }
-
- static void infood(){
- while(true)
- {
- System.out.print("是否要录入商品(是输入1/否输入0):");
- int d = in.nextInt();
- if(d == 1) {
- String[] a = new String[4];
- String ch;
- System.out.print("请输入商品的名称:");
- a[0] = in.next();
- System.out.print("请输入商品的颜色:");
- a[1] = in.next();
- System.out.print("请输入商品的价格:");
- a[2] = in.next();
- System.out.print("请输入商品的数量:");
- a[3] = in.next();
- ch = "名称:" + a[0] + " 颜色:" + a[1] + " 价格:" + a[2] + " 数量:" + a[3];
- link.add(ch);
- System.out.println("商品录入成功");
- showfood();
- }
- else
- return;
- }
- }
-
- static void showfood(){
- if(link.isEmpty())
- {
- System.out.println("库房没有商品");
- return;
- }
- System.out.println("所有商品如下:");
- int j = 0;
- for(Object str : link)
- {
- System.out.print("编号(" + ++j + "): " );
- System.out.println(str);
- }
- }
-
- static void delfood(){
- while(true) {
- System.out.print("请输入需要删除的商品编号(输入0退出):");
-
- int num = in.nextInt();
- if(num == 0)
- break;
- link.remove(num - 1);
- }
- showfood();
- }
- }

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。