java作业2.商品管理系统重写

发布时间 2023-09-15 10:39:59作者: 牟兆迪
  1 ## 商品管理系统重写
  2 
  3 ~~~java
  4 package test03;
  5 
  6 public class WarehouseInformation {
  7     private String itemno;//编号
  8     private String itemname;//名字
  9     private String suppliername;//供应商
 10     private String warehousingtime;//入库时间
 11     private String shipmenttime;//出库时间
 12     private String warehousenumber;//仓库号
 13     private String warehouseplace;//具体位置
 14     private int itemnumber;//入库数量
 15     private int outnumber;//出库数量
 16 
 17     public WarehouseInformation() {
 18         this.itemno = "";
 19         this.itemname = "";
 20         this.suppliername = "";
 21         this.warehousingtime = "";
 22         this.shipmenttime = "";
 23         this.warehousenumber = "";
 24         this.warehouseplace = "";
 25         this.itemnumber = 0;
 26         this.outnumber = 0;
 27     }
 28 
 29     public String getItemno() {
 30         return itemno;
 31     }
 32 
 33     public void setItemno(String itemno) {
 34         if(itemno.length() != 8){
 35             System.out.println("itemno输入格式有误,该项设置失败");
 36         }
 37         else{
 38             this.itemno = itemno;
 39         }
 40     }
 41 
 42     public String getItemname() {
 43         return itemname;
 44     }
 45 
 46     public void setItemname(String itemname) {
 47         this.itemname = itemname;
 48     }
 49 
 50     public String getSuppliername() {
 51         return suppliername;
 52     }
 53 
 54     public void setSuppliername(String suppliername) {
 55         this.suppliername = suppliername;
 56     }
 57 
 58     public String getWarehousingtime() {
 59         return warehousingtime;
 60     }
 61 
 62     public void setWarehousingtime(String warehousingtime) {
 63         if(warehousingtime.length() != 8){
 64             System.out.println("warehousingtime输入格式有误,该项设置失败");
 65         }
 66        else {
 67             this.warehousingtime = warehousingtime;
 68         }
 69     }
 70 
 71     public String getShipmenttime() {
 72         return shipmenttime;
 73     }
 74 
 75     public void setShipmenttime(String shipmenttime) {
 76         if(shipmenttime.length() != 8){
 77             System.out.println("shipmenttime输入格式有误,该项设置失败");
 78         }
 79         else{
 80             this.shipmenttime = shipmenttime;
 81         }
 82     }
 83 
 84     public String getWarehousenumber() {
 85         return warehousenumber;
 86     }
 87 
 88     public void setWarehousenumber(String warehousenumber) {
 89         if(warehousenumber.length() != 3){
 90             System.out.println("warehousenumber输入格式有误,该项设置失败");
 91         }
 92         else{
 93             this.warehousenumber = warehousenumber;
 94         }
 95     }
 96 
 97     public String getWarehouseplace() {
 98         return warehouseplace;
 99     }
100 
101     public void setWarehouseplace(String warehouseplace) {
102         if(warehouseplace.length() != 8){
103             System.out.println("warehouseplace输入格式有误,该项设置失败");
104         }
105         else{
106             this.warehouseplace = warehouseplace;
107         }
108 
109     }
110 
111     public int getItemnumber() {
112         return itemnumber;
113     }
114 
115     public void setItemnumber(int itemnumber) {
116         this.itemnumber = itemnumber;
117     }
118 
119     public int getOutnumber() {
120         return outnumber;
121     }
122 
123     public void setOutnumber(int outnumber) {
124         this.outnumber = outnumber;
125     }
126 
127     public WarehouseInformation(String itemno, String itemname, String suppliername, String warehousingtime, String shipmenttime, String warehousenumber, String warehouseplace, int itemnumber, int outnumber) {
128         this.itemno = itemno;
129         this.itemname = itemname;
130         this.suppliername = suppliername;
131         this.warehousingtime = warehousingtime;
132         this.shipmenttime = shipmenttime;
133         this.warehousenumber = warehousenumber;
134         this.warehouseplace = warehouseplace;
135         this.itemnumber = itemnumber;
136         this.outnumber = outnumber;
137     }
138     public  void showInformation()
139     {
140         System.out.println("*******************************************");
141         System.out.println("     石家庄铁道大学前进22软工开发有限公司");
142         System.out.println("              仓库管理系统2022版");
143         System.out.println("*******************************************");
144         System.out.println("               1、商品编号:" + this.getItemno());
145         System.out.println("              2、商品名称:" + this.getItemname());
146         System.out.println("            3、供货商信息:" + this.getSuppliername());
147         System.out.println("           4、入库时间:" + this.getWarehousingtime());
148         System.out.println("            5、存放仓库号:" + this.getWarehousenumber());
149         System.out.println("           6、存放位置信息:" + this.getWarehouseplace());
150         System.out.println("           7、入库商品数量:" + this.getItemnumber());
151     }
152 }
153 
154 ~~~
155 
156 ~~~java 
157 package test03;
158 import java.util.Scanner;
159 public class WarehouseManagement {
160     static int N = 0;
161     public static void main(String[] args) {
162         Scanner scanner = new Scanner(System.in);
163         WarehouseInformation[] w = new WarehouseInformation[5];
164         for(int i = 0;i<5;i++){
165             w[i] = new WarehouseInformation();
166         }
167         while (true) {
168             print();
169             System.out.print("请输入选项:");
170             int choice = scanner.nextInt();
171             scanner.nextLine();
172             switch (choice) {
173                 case 1:
174                     InHouse(scanner, w);
175                     break;
176                 case 2:
177                     ReviseInformation(scanner,w);
178                     break;
179                 case 3:
180 
181                     OutHouse(scanner,w);
182                     break;
183                 case 4:
184                     show(scanner,w);
185                     break;
186                 default:
187                     System.out.println("该选项不存在");
188                     break;
189             }
190         }
191     }
192     static void InHouse(Scanner scanner, WarehouseInformation[] w) {
193         WarehouseInformation tmp = new WarehouseInformation();
194         tmp = w[N];
195         int n1 = 8;
196         int n2 = 3;
197         boolean flag = true;
198         String itemno = "";
199         String warehousingtime = "";
200         String warehousenumber ="";
201         String warehouseplace = "";
202 
203         System.out.print("请输入商品编号:");
204         itemno = inLegal(flag,n1,itemno,scanner);
205         flag = true;
206 
207         System.out.print("请输入商品名称:");
208         String itemname = scanner.nextLine();
209 
210         System.out.print("请输入供货商信息:");
211         String suppliername = scanner.nextLine();
212 
213         System.out.print("请输入入库时间:");
214         warehousingtime = inLegal(flag,n1,warehousingtime,scanner);
215         flag = true;
216 
217         System.out.print("请输入存放仓库号:");
218         warehousenumber = inLegal(flag,n2,warehousenumber,scanner);
219         flag = true;
220 
221         System.out.print("请输入存放位置信息:");
222         warehouseplace = inLegal(flag,n1,warehouseplace,scanner);
223         flag = true;
224 
225         System.out.print("请输入入库商品数量:");
226         int itemnumber = scanner.nextInt();
227         scanner.nextLine();
228 
229         inprint(itemno,itemname,suppliername,warehousingtime,warehousenumber,warehouseplace,itemnumber);
230 
231         String c = scanner.nextLine();
232         if (c.equals("Y")) {
233             N++;
234             tmp.setItemno(itemno);
235             tmp.setItemname(itemname);
236             tmp.setSuppliername(suppliername);
237             tmp.setWarehousingtime(warehousingtime);
238             tmp.setWarehousenumber(warehousenumber);
239             tmp.setWarehouseplace(warehouseplace);
240             tmp.setItemnumber(itemnumber);
241             System.out.println("保存成功");
242             return;
243         } else {
244             return;
245         }
246     }
247 
248     static void ReviseInformation(Scanner scanner, WarehouseInformation[] w) {
249         WarehouseInformation tmp = new WarehouseInformation();
250         boolean flag1 = true;
251         while (true) {
252             System.out.println("*******************************************");
253             System.out.println("     石家庄铁道大学前进22软工开发有限公司");
254             System.out.println("              仓库管理系统2022版");
255             System.out.println("*******************************************");
256             System.out.print("           请输入商品编号(输入111退出):");
257             String b = scanner.nextLine();
258             if(b.equals("111")) return;
259             for (int i = 0; i < 5; i++) {
260                 tmp = w[i];
261                 if (b.equals(tmp.getItemno())) {
262                     flag1 = false;
263                     tmp.showInformation();
264                     System.out.print("        请输入需要修改的信息编号(1-7):");
265                     int choice = scanner.nextInt();
266                     scanner.nextLine();
267                     switch (choice) {
268                         case 1:
269                             Revise(choice,tmp,scanner);
270                             break;
271                         case 2:
272                             Revise(choice,tmp,scanner);
273                             break;
274                         case 3:
275                             Revise(choice,tmp,scanner);
276                             break;
277                         case 4:
278                             Revise(choice,tmp,scanner);
279                             break;
280                         case 5:
281                             Revise(choice,tmp,scanner);
282                             break;
283                         case 6:
284                             Revise(choice,tmp,scanner);
285                             break;
286                         case 7:
287                             System.out.print("请输入修改后的入库商品数量:");
288                             int qi = scanner.nextInt();
289                             scanner.nextLine();
290                             System.out.println("是否保存信息(Y/N):");
291                             String a7 = scanner.nextLine();
292                             if (a7.equals("Y")) {
293                                 tmp.setItemnumber(qi);
294                                 System.out.println("保存成功");
295                                 return;
296                             }
297                             scanner.nextLine();
298                             break;
299                         default:
300                             System.out.println("该选项不存在");
301                             scanner.nextLine();
302                             return;
303                     }
304                     System.out.println("*******************************************");
305                 }
306             }
307             if(flag1){
308                 System.out.println("库中没有该商品");
309                 return;
310             }
311         }
312     }
313     static void OutHouse(Scanner scanner, WarehouseInformation[] w) {
314         WarehouseInformation tmp = new WarehouseInformation();
315         boolean flag = true;
316         while (true) {
317             System.out.println("*******************************************");
318             System.out.println("     石家庄铁道大学前进22软工开发有限公司");
319             System.out.println("              仓库管理系统2022版");
320             System.out.println("*******************************************");
321             System.out.print("           请输入商品编号(输入111退出):");
322             String b = scanner.nextLine();
323             if(b.equals("111")) return;
324             for (int i = 0; i < 5; i++) {
325                 tmp = w[i];
326                 if (b.equals(tmp.getItemno())) {
327                     flag = false;
328                     tmp.showInformation();
329                     System.out.print("           请输入出库时间:");
330                     String shipmenttime = scanner.nextLine();
331                     int outTime = Integer.parseInt(shipmenttime);
332                     int inTime = Integer.parseInt(tmp.getWarehousingtime());
333                     if(outTime<inTime){
334                         System.out.println("出库时间不得小于入库时间");
335                         return;
336                     }
337                     System.out.print("           请输入出库数量:");
338                     int outnumber = scanner.nextInt();
339                     scanner.nextLine();
340                     int sumNumber = tmp.getItemnumber()-tmp.getOutnumber();
341                     if(outnumber>sumNumber){
342                         System.out.println("出库数量不得大于库存数量");
343                         return;
344                     }
345                     System.out.print("是否保存信息(Y/N):");
346                     String flag1 = scanner.nextLine();
347                     if (flag1.equals("Y")) {
348                         tmp.setShipmenttime(shipmenttime);
349                         int num = tmp.getItemnumber();
350                         tmp.setOutnumber(outnumber);
351                         System.out.println("保存成功");
352                         return;
353                     }
354                     else{
355                         System.out.println("未保存,已退出");
356                         return;
357                     }
358                 }
359             }
360         }
361     }
362     static void show(Scanner scanner, WarehouseInformation[] w)
363     {
364         WarehouseInformation tmp = new WarehouseInformation();
365         for(int i = 0;i<5;i++)
366         {
367             tmp = w[i];
368             System.out.println("商品编号:"+tmp.getItemno()+"  商品名称:"+tmp.getItemname()+"  库存数量:"+(tmp.getItemnumber()-tmp.getOutnumber()));
369         }
370     }
371     static void print(){
372         System.out.println("*******************************************");
373         System.out.println("     石家庄铁道大学前进22软工开发有限公司");
374         System.out.println("              仓库管理系统2022版");
375         System.out.println("*******************************************");
376         System.out.println("         1、商品入库管理");
377         System.out.println("         2、商品信息修改");
378         System.out.println("         3、商品出库管理");
379         System.out.println("         4、仓库盘点管理");
380         System.out.println("*******************************************");
381     }
382     static void inprint(String itemno,String itemname,String suppliername,String warehousingtime,String warehousenumber,String warehouseplace,int itemnumber){
383         System.out.println("*******************************************");
384         System.out.println("     石家庄铁道大学前进22软工开发有限公司");
385         System.out.println("              仓库管理系统2022版");
386         System.out.println("*******************************************");
387         System.out.println("               商品编号:" + itemno);
388         System.out.println("              商品名称:" + itemname);
389         System.out.println("            供货商信息:" + suppliername);
390         System.out.println("           入库时间:" + warehousingtime);
391         System.out.println("            存放仓库号:" + warehousenumber);
392         System.out.println("           存放位置信息:" + warehouseplace);
393         System.out.println("           入库商品数量:" + itemnumber);
394         System.out.println("       该商品入库操作已完成,是否提交(Y/N)");
395         System.out.println("*******************************************");
396     }
397     static void add(Scanner scanner,WarehouseInformation[] w){
398         WarehouseInformation tmp1 = new WarehouseInformation();
399         WarehouseInformation tmp2 = new WarehouseInformation();
400         for(int i = 0;i<5;i++){
401             tmp1 = w[i];
402             for(int j = 1;j<5;j++){
403                 tmp2 = w[j];
404                 if(i!=j&&tmp1.getItemno().equals(tmp2.getItemno())){
405                     tmp1.setItemnumber(tmp1.getItemnumber()+tmp2.getItemnumber());
406                     tmp2.setItemnumber(tmp1.getItemnumber()+tmp2.getItemnumber());
407                 }
408             }
409         }
410     }
411     static String inLegal(boolean flag,int n,String s,Scanner scanner){
412         while (flag) {
413             s = scanner.nextLine();
414             if (s.length() != n) {
415                 System.out.print("输入格式有误,请重新输入:");
416             } else {
417                 flag = false;
418             }
419         }
420         return s;
421     }
422     static void Revise(int choice,WarehouseInformation tmp ,Scanner scanner){
423         System.out.print("请输入修改后的商品信息:");
424         String revise = scanner.nextLine();
425         System.out.println("是否保存信息(Y/N):");
426         String flag = scanner.nextLine();
427         if (flag.equals("Y")) {
428             switch(choice){
429                 case 1:
430                     tmp.setItemno(revise);
431                     break;
432                 case 2:
433                     tmp.setItemname(revise);
434                     break;
435                 case 3:
436                     tmp.setSuppliername(revise);
437                     break;
438                 case 4:
439                     tmp.setWarehousingtime(revise);
440                     break;
441                 case 5:
442                     tmp.setWarehousenumber(revise);
443                     break;
444                 case 6:
445                     tmp.setWarehouseplace(revise);
446                     break;
447             }
448             System.out.println("保存成功");
449         }
450     }
451 }