每日汇报 第二周第二天 JAVA验证码程序完成

今日学习:

  完成了JAVA验证码程序的调试实现,把之前的代码优化发了。

  1 package org.ERPsystem;
  2 
  3 import org.apache.commons.lang3.StringUtils;
  4 
  5 import java.time.LocalDate;
  6 import java.time.format.DateTimeFormatter;
  7 import java.util.ArrayList;
  8 import java.util.List;
  9 import java.util.Scanner;
 10 
 11 public class WarehouseManagement {
 12     public static List<WarehouseInformation> informationList = new ArrayList<>();
 13 
 14     static int totalWidth = 55;
 15 
 16     public static void main(String[] args) {
 17         Scanner scanner = new Scanner(System.in);
 18         int userInput;
 19 
 20         while (true) {
 21             displayMainMenu();
 22             userInput = scanner.nextInt();
 23             scanner.nextLine();
 24             switch (userInput) {
 25                 case 1:
 26                     WarehousingManagement(scanner);
 27                     break;
 28                 case 2:
 29                     productInformationModification(scanner);
 30                     break;
 31                 case 3:
 32                     productOutboundManagement(scanner);
 33                     break;
 34                 case 4:
 35                     warehouseInventory(scanner);
 36                     break;
 37                 case 5:
 38                     scanner.close();
 39                     return;
 40                 default:
 41                     System.out.println("该选项不存在");
 42             }
 43         }
 44 
 45 
 46     }
 47 
 48 
 49     private static void displayMainMenu() {
 50         System.out.println("***********************************************************");
 51         System.out.println(StringUtils.center("石家庄铁道大学前进22软件开发有限公司", totalWidth));
 52         System.out.println(StringUtils.center("仓库管理系统2022版", totalWidth));
 53         System.out.println("***********************************************************");
 54         System.out.println(StringUtils.center("1、商品入库管理", totalWidth));
 55         System.out.println(StringUtils.center("2、商品信息修改", totalWidth));
 56         System.out.println(StringUtils.center("3、商品出库管理", totalWidth));
 57         System.out.println(StringUtils.center("4、仓库盘点管理", totalWidth));
 58         System.out.println(StringUtils.center("5、退出系统", totalWidth));
 59         System.out.println("***********************************************************");
 60     }
 61 
 62     private static void WarehousingManagement(Scanner scanner) {
 63 
 64         String userInput;
 65         String result;
 66         StringBuilder s1 = new StringBuilder();
 67         WarehouseInformation warehouseInformation = new WarehouseInformation();
 68 
 69         while (true) {
 70             while (true){
 71                 System.out.println("请输入入库商品编码:(8位数字)");
 72                 userInput = scanner.nextLine();
 73                 if(isValidEightDigit(userInput)){
 74                     warehouseInformation.setItemno(userInput);
 75                     System.out.println("商品编号录入成功:" + userInput);
 76                     break;
 77                 }else {
 78                     System.out.println("录入错误,请重新录入正确的商品编号。");
 79                 }
 80             }
 81             System.out.println("请输入入库商品名称:");
 82             userInput = scanner.nextLine();
 83             warehouseInformation.setItemname(userInput);
 84             System.out.println("商品名称录入成功:" + userInput);
 85 
 86             System.out.println("请输入入库商品供货商信息:");
 87             userInput = scanner.nextLine();
 88             warehouseInformation.setSuppliername(userInput);
 89             System.out.println("商品供货商信息录入成功:" + userInput);
 90 
 91             while (true){
 92                 System.out.println("请输入商品入库时间:(8位数字)");
 93                 userInput = scanner.nextLine();
 94                 if(isValidEightDigit(userInput)){
 95                     warehouseInformation.setWarehousingtime(userInput);
 96                     System.out.println("商品入库时间录入成功:" + userInput);
 97                     break;
 98                 }else {
 99                     System.out.println("录入错误,请重新录入正确的商品入库时间。");
100                 }
101             }
102 
103             while (true){
104                 System.out.println("请输入商品仓库号:(3位数字)");
105                 userInput = scanner.nextLine();
106                 if(isValidThreeDigit(userInput)){
107                     warehouseInformation.setWarehousenumber(userInput);
108                     System.out.println("商品仓库号信息录入成功:" + userInput);
109                     break;
110                 }else {
111                     System.out.println("录入错误,请重新录入正确的商品仓库号。");
112                 }
113             }
114 
115             while (true){
116                 System.out.println("请输入商品存放位置信息:(8位数字)");
117                 userInput = scanner.nextLine();
118                 if(isValidEightDigit(userInput)){
119                     warehouseInformation.setWarehouseplace(userInput);
120                     System.out.println("商品存放位置信息录入成功:" + userInput);
121                     break;
122                 }else {
123                     System.out.println("录入错误,请重新录入正确的商品存放位置。");
124                 }
125             }
126 
127             System.out.println("请输入商品入库数量:");
128             userInput = scanner.nextLine();
129             warehouseInformation.setItemnumber(Integer.parseInt(userInput));
130             System.out.println("商品入库数量信息录入成功:" + userInput);
131 
132             System.out.println("***********************************************************");
133             System.out.println(StringUtils.center("石家庄铁道大学前进22软件开发有限公司", totalWidth));
134             System.out.println(StringUtils.center("仓库管理系统2022版", totalWidth));
135             System.out.println("***********************************************************");
136 
137             s1.append("商品编号:").append(warehouseInformation.getItemno());
138             result = s1.toString();
139             s1.setLength(0);
140             System.out.println(StringUtils.center(result, totalWidth));
141 
142             s1.append("商品名称:").append(warehouseInformation.getItemname());
143             result = s1.toString();
144             s1.setLength(0);
145             System.out.println(StringUtils.center(result, totalWidth));
146 
147             s1.append("商品供货商信息:").append(warehouseInformation.getSuppliername());
148             result = s1.toString();
149             s1.setLength(0);
150             System.out.println(StringUtils.center(result, totalWidth));
151 
152             s1.append("商品入库时间:").append(warehouseInformation.getWarehousingtime());
153             result = s1.toString();
154             s1.setLength(0);
155             System.out.println(StringUtils.center(result, totalWidth));
156 
157             s1.append("存放仓库号:").append(warehouseInformation.getWarehousenumber());
158             result = s1.toString();
159             s1.setLength(0);
160             System.out.println(StringUtils.center(result, totalWidth));
161 
162             s1.append("商品存放位置信息:").append(warehouseInformation.getWarehouseplace());
163             result = s1.toString();
164             s1.setLength(0);
165             System.out.println(StringUtils.center(result, totalWidth));
166 
167             s1.append("商品入库数量:").append(warehouseInformation.getItemnumber());
168             result = s1.toString();
169             s1.setLength(0);
170             System.out.println(StringUtils.center(result, totalWidth));
171 
172             System.out.println(StringUtils.center("该商品入库操作已完成,是否提交(Y/N)", totalWidth));
173             System.out.println("***********************************************************");
174 
175             userInput= scanner.nextLine();
176             if(userInput.equals("Y")){
177                 informationList.add(warehouseInformation);
178                 return;
179             }else {
180                     warehouseInformation = null;
181                     scanner.nextLine();
182 
183             }
184         }
185 
186     }
187 
188     public static boolean isValidEightDigit(String itemno) {
189         if (itemno.length() != 8) {
190             return false;
191         }
192         for (char c : itemno.toCharArray()) {
193             if (!Character.isDigit(c)) {
194                 return false;
195             }
196         }
197         return true;
198     }
199 
200     public static boolean isValidThreeDigit(String itemno) {
201         if (itemno.length() != 3) {
202             return false;
203         }
204         for (char c : itemno.toCharArray()) {
205             if (!Character.isDigit(c)) {
206                 return false;
207             }
208         }
209         return true;
210     }
211 
212     private static void productInformationModification(Scanner scanner) {
213         StringBuilder s1=new StringBuilder();
214         String result;
215         String userInput;
216         while (true){
217             System.out.println("***********************************************************");
218             System.out.println(StringUtils.center("石家庄铁道大学前进22软件开发有限公司", totalWidth));
219             System.out.println(StringUtils.center("仓库管理系统2022版", totalWidth));
220             System.out.println("***********************************************************");
221             System.out.println(StringUtils.center("请输入商品编号:XXXXXXXX", totalWidth));
222             System.out.println("***********************************************************");
223 
224             userInput = scanner.nextLine();
225 
226 
227             WarehouseInformation foundInformation = findInformationWay (informationList,userInput);
228 
229             if (foundInformation!=null) {
230                 System.out.println("***********************************************************");
231                 System.out.println(StringUtils.center("石家庄铁道大学前进22软件开发有限公司", totalWidth));
232                 System.out.println(StringUtils.center("仓库管理系统2022版", totalWidth));
233                 System.out.println("***********************************************************");
234 
235                 s1.append("商品编号:").append(foundInformation.getItemno());
236                 result = s1.toString();
237                 s1.setLength(0);
238                 System.out.println(StringUtils.center(result, totalWidth));
239 
240                 s1.append("商品名称:").append(foundInformation.getItemname());
241                 result = s1.toString();
242                 s1.setLength(0);
243                 System.out.println(StringUtils.center(result, totalWidth));
244 
245                 s1.append("商品供货商信息:").append(foundInformation.getSuppliername());
246                 result = s1.toString();
247                 s1.setLength(0);
248                 System.out.println(StringUtils.center(result, totalWidth));
249 
250                 s1.append("商品入库时间:").append(foundInformation.getWarehousingtime());
251                 result = s1.toString();
252                 s1.setLength(0);
253                 System.out.println(StringUtils.center(result, totalWidth));
254 
255                 s1.append("存放仓库号:").append(foundInformation.getWarehousenumber());
256                 result = s1.toString();
257                 s1.setLength(0);
258                 System.out.println(StringUtils.center(result, totalWidth));
259 
260                 s1.append("商品存放位置信息:").append(foundInformation.getWarehouseplace());
261                 result = s1.toString();
262                 s1.setLength(0);
263                 System.out.println(StringUtils.center(result, totalWidth));
264 
265                 s1.append("商品入库数量:").append(foundInformation.getItemnumber());
266                 result = s1.toString();
267                 s1.setLength(0);
268                 System.out.println(StringUtils.center(result, totalWidth));
269 
270                 System.out.println(StringUtils.center("请选择需要修改的信息编号(1-7):", totalWidth));
271                 System.out.println("***********************************************************");
272 
273                 int userInputid = scanner.nextInt();
274                 switch (userInputid){
275                     case 1:
276                         System.out.println("请输入新的商品名称:");
277                         scanner.nextLine();
278                         userInput = scanner.nextLine();
279                         foundInformation.setItemno(userInput);
280                         System.out.println("修改完成!");
281                         break;
282                         case 2:
283                             System.out.println("请输入新的商品供货商信息:");
284                             scanner.nextLine();
285                             userInput = scanner.nextLine();
286                             foundInformation.setSuppliername(userInput);
287                             System.out.println("修改完成!");
288                             break;
289                         case 3:
290                             System.out.println("请输入新的商品入库时间:");
291                             scanner.nextLine();
292                             userInput = scanner.nextLine();
293                             foundInformation.setWarehousingtime(userInput);
294                             System.out.println("修改完成!");
295                             break;
296                         case 4:
297                             System.out.println("请输入新的存放仓库号:");
298                             scanner.nextLine();
299                             userInput = scanner.nextLine();
300                             foundInformation.setWarehousenumber(userInput);
301                             System.out.println("修改完成!");
302                             break;
303                         case 5:
304                             System.out.println("请输入新的商品存放位置信息:");
305                             scanner.nextLine();
306                             userInput = scanner.nextLine();
307                             foundInformation.setWarehouseplace(userInput);
308                             System.out.println("修改完成!");
309                             break;
310                         case 6:
311                             System.out.println("请输入新的商品入库数量:");
312                             scanner.nextLine();
313                             userInput = scanner.nextLine();
314                             foundInformation.setItemnumber(Integer.parseInt(userInput));
315                             System.out.println("修改完成!");
316                             break;
317                         case 7:
318                             System.out.println("请输入新的商品名称:");
319                             scanner.nextLine();
320                             userInput = scanner.nextLine();
321                             foundInformation.setItemname(userInput);
322                             System.out.println("修改完成!");
323                             break;
324                         default:
325                             System.out.println("请输入正确的编号!");
326                             break;
327                 }
328                 return;
329             }else {
330                 System.out.println("请输入正确的编号!");
331             }
332 
333         }
334 
335     }
336 
337     public static WarehouseInformation findInformationWay (List<WarehouseInformation>informationList,String userInput) {
338         for (WarehouseInformation student : informationList) {
339             if(student.getItemno().equals(userInput)) {
340                 return student;
341             }
342         }
343         return null;
344     }
345 
346     private static void productOutboundManagement(Scanner scanner) {
347         StringBuilder s1 = new StringBuilder();
348         String result;
349         String userInput;
350 
351         while (true) {
352             System.out.println("***********************************************************");
353             System.out.println(StringUtils.center("石家庄铁道大学前进22软件开发有限公司", totalWidth));
354             System.out.println(StringUtils.center("仓库管理系统2022版", totalWidth));
355             System.out.println("***********************************************************");
356             System.out.println(StringUtils.center("请输入商品编号:XXXXXXXX", totalWidth));
357             System.out.println("***********************************************************");
358 
359             userInput = scanner.nextLine();
360 
361 
362             WarehouseInformation foundInformation = findInformationWay(informationList, userInput);
363 
364             if (foundInformation != null) {
365                 System.out.println("***********************************************************");
366                 System.out.println(StringUtils.center("石家庄铁道大学前进22软件开发有限公司", totalWidth));
367                 System.out.println(StringUtils.center("仓库管理系统2022版", totalWidth));
368                 System.out.println("***********************************************************");
369 
370                 s1.append("商品编号:").append(foundInformation.getItemno());
371                 result = s1.toString();
372                 s1.setLength(0);
373                 System.out.println(StringUtils.center(result, totalWidth));
374 
375                 s1.append("商品名称:").append(foundInformation.getItemname());
376                 result = s1.toString();
377                 s1.setLength(0);
378                 System.out.println(StringUtils.center(result, totalWidth));
379 
380                 s1.append("商品供货商信息:").append(foundInformation.getSuppliername());
381                 result = s1.toString();
382                 s1.setLength(0);
383                 System.out.println(StringUtils.center(result, totalWidth));
384 
385                 s1.append("商品入库时间:").append(foundInformation.getWarehousingtime());
386                 result = s1.toString();
387                 s1.setLength(0);
388                 System.out.println(StringUtils.center(result, totalWidth));
389 
390                 s1.append("存放仓库号:").append(foundInformation.getWarehousenumber());
391                 result = s1.toString();
392                 s1.setLength(0);
393                 System.out.println(StringUtils.center(result, totalWidth));
394 
395                 s1.append("商品存放位置信息:").append(foundInformation.getWarehouseplace());
396                 result = s1.toString();
397                 s1.setLength(0);
398                 System.out.println(StringUtils.center(result, totalWidth));
399 
400                 s1.append("商品入库数量:").append(foundInformation.getItemnumber());
401                 result = s1.toString();
402                 s1.setLength(0);
403                 System.out.println(StringUtils.center(result, totalWidth));
404                 System.out.println(StringUtils.center("出库时间:XXXXXXXXX", totalWidth));
405                 System.out.println(StringUtils.center("出库数量:xxx", totalWidth));
406                 System.out.println("***********************************************************");
407 
408                 while (true) {
409                     System.out.println("请输入出库时间:(8位数字)");
410 
411                     userInput = scanner.nextLine();
412                     LocalDate currentDate = LocalDate.now();
413                     DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
414                     LocalDate OutputDate = LocalDate.parse(userInput, formatter);
415                     LocalDate inputDate = LocalDate.parse(foundInformation.getWarehousingtime(), formatter);
416                     if (isValidEightDigit(userInput)) {
417 
418                             if (currentDate.isAfter(OutputDate) && OutputDate.isAfter(inputDate)) {
419                                 foundInformation.setShipmenttime(userInput);
420                                 System.out.println("商品出库时间录入成功:" + userInput);
421                                 while (true) {
422                                     System.out.println("请输入出库数量:(不得超过当前库中数量)");
423                                     userInput = scanner.nextLine();
424                                     if (isExceedingStorage(foundInformation, Integer.parseInt(userInput))) {
425                                         foundInformation.setOutnumber(Integer.parseInt(userInput));
426                                         System.out.println("商品出库数量录入成功:" + userInput);
427                                         break;
428                                     } else {
429                                         System.out.println("录入错误,请重新录入正确的出库数量。");
430                                     }
431                                 }
432                                 break;
433                             } else {
434                                 System.out.println("操作失败,出库时间不合规");
435                             }
436 
437                     } else {
438                         System.out.println("请输入正确的编号!");
439                     }
440 
441                 }
442             }else {
443                 System.out.println("库中没有该商品");
444             }
445 
446 
447             break;
448         }
449 
450 
451     }
452 
453     public static boolean isExceedingStorage(WarehouseInformation information,int userInput) {
454         if (userInput > information.getItemnumber()) {
455             return false;
456         }
457         return true;
458     }
459 
460     private static void warehouseInventory(Scanner scanner) {
461         int count = 1;
462 
463         System.out.println("***********************************************************");
464         System.out.println(StringUtils.center("石家庄铁道大学前进22软件开发有限公司", totalWidth));
465         System.out.println(StringUtils.center("仓库管理系统2022版", totalWidth));
466         System.out.println("***********************************************************");
467         for(WarehouseInformation information :informationList) {
468             int sum= information.getItemnumber()-information.getOutnumber();
469             System.out.println(count+"、商品编号"+information.getItemno()+"、商品名称:"+information.getItemname()+
470                     "、库存数量"+sum);
471             count++;
472         }
473         System.out.println("***********************************************************");
474     }
475 
476 
477 }

数据结构就不发了

明日计划:

  学习JAVAweb中的servlet和前后端联动。

遇到困难:Javaweb学习

posted @ 2023-09-12 20:23  起名字真难_qmz  阅读(15)  评论(0)    收藏  举报