完善的开学测试
//淦了,插入代码之前没写东西,退不出来了。。。
//只能说,该完成的都有,但是说,真正彻底实现这个所谓项目,还需数据库(maybe)等的学习
//博客园不能插入文档,题目就不放进来了
1 import java.util.Scanner; 2 3 //第一次分解 执行类: 4 public class WarehouseManagement2 { 5 public static void main(String[] args) { 6 //第二次分解 仓库信息: 7 WarehouseInformation2[] warehouse2= new WarehouseInformation2[20]; 8 warehouse2[0] = new WarehouseInformation2(); 9 10 //第三次分解 主界面方法: 11 mainFrame(warehouse2); 12 13 } 14 //工具类方法定义 15 //第二次分解 新增数据: 16 public static void addData(WarehouseInformation2[] warehouse2){ 17 // 暂未解决: 新增数据的 “下一条” 问题 18 19 Scanner sc = new Scanner(System.in); 20 while(true){ 21 System.out.println("请录入商品编号:"); 22 String sitemno = sc.next(); 23 boolean b1 = geshi(sitemno); //判断格式是否正确 24 if(b1){ 25 warehouse2[0].setItemno(sitemno); //商品编号 26 break; 27 }else{ 28 System.out.println("格式错误,请重新录入"); 29 } 30 } 31 // sout(arr); //我对自己的想法进行保留,但是代码忘记多不多了,也懒得弄了 32 //sout()之前是一个界面输出的方法 33 34 System.out.println("请录入商品名称:"); 35 String itemname = sc.next(); 36 warehouse2[0].setItemname(itemname); //商品名称 37 // sout(arr); 38 39 System.out.println("请录入供货商信息:"); 40 String suppliername = sc.next(); //供货商信息 41 warehouse2[0].setSuppliername(suppliername); 42 // sout(arr); 43 44 while(true){ 45 System.out.println("请录入入库时间:"); 46 String warehousingtime = sc.next(); //入库时间 47 boolean b2 = geshi(warehousingtime); //判断格式是否正确 48 if(b2){ 49 warehouse2[0].setWarehousingtime(warehousingtime); 50 break; 51 }else{ 52 System.out.println("格式错误,请重新录入"); 53 } 54 } 55 // sout(arr); 56 57 while(true){ 58 System.out.println("请录入存放仓库号:"); 59 String warehousenumber = sc.next(); //仓库编号 60 boolean b3 = geshi(warehousenumber); 61 if(b3){ 62 warehouse2[0].setWarehousenumber(warehousenumber); 63 break; 64 }else{ 65 System.out.println("格式错误,请重新录入"); 66 } 67 } 68 // sout(arr); 69 70 while(true){ 71 System.out.println("请录入商品存放位置信息:"); 72 String warehouseplace = sc.next(); //商品位置信息 73 boolean b = geshi(warehouseplace); //判断格式是否正确 74 if (b) { 75 warehouse2[0].setWarehouseplace(warehouseplace); 76 break; 77 } else { 78 System.out.println("格式错误,请重新录入"); 79 } 80 } 81 // sout(arr); 82 83 System.out.println("请录入商品入库数量:"); 84 int itemnumber = sc.nextInt(); //入库数量 85 warehouse2[0].setItemnumber(itemnumber); 86 } 87 88 //第二次分解 数据修改: 89 public static void modifyData(WarehouseInformation2[] warehouse2){ 90 Scanner sc = new Scanner(System.in); 91 bian:while(true) { 92 System.out.println("请输入(八位)商品编号:"); 93 //可以加个判断语句,但是没要求,我也懒得加 94 95 String innumber = sc.next(); 96 for (int i = 0; i < warehouse2.length; i++) { 97 if (warehouse2[i].getItemno().equals(innumber)) { 98 System.out.println("***********************************************************"); 99 System.out.println(" 石家庄铁道大学前进22软件开发有限公司"); 100 System.out.println(" 仓库管理系统2022版"); 101 System.out.println("***********************************************************"); 102 System.out.println(" 1、商品编号:" + warehouse2[0].getItemno()); 103 System.out.println(" 2、商品名称:" + warehouse2[0].getItemname()); 104 System.out.println(" 3、供货商信息:" + warehouse2[0].getSuppliername()); 105 System.out.println(" 4、入库时间:" + warehouse2[0].getWarehousingtime()); 106 System.out.println(" 5、存放仓库号:" + warehouse2[0].getWarehousenumber()); 107 System.out.println(" 6、存放位置信息:" + warehouse2[0].getWarehouseplace()); 108 System.out.println(" 7、入库商品数量:" + warehouse2[0].getItemnumber()); 109 System.out.println("**********************************************************"); 110 System.out.println(" 请选择需要修改的内容:"); //choose3 111 break bian; 112 } 113 } 114 } 115 int choose3 = sc.nextInt(); 116 switch (choose3) { 117 case 1 -> { 118 System.out.println("请修改:"); 119 String n1 = sc.next(); 120 warehouse2[0].setItemno(n1); 121 } 122 case 2 -> { 123 System.out.println("请修改:"); 124 String n2 = sc.next(); 125 warehouse2[0].setItemname(n2); 126 } 127 case 3 -> { 128 System.out.println("请修改:"); 129 String n3 = sc.next(); 130 warehouse2[0].setSuppliername(n3); 131 } 132 case 4 -> { 133 System.out.println("请修改:"); 134 String n4 = sc.next(); 135 warehouse2[0].setWarehousingtime(n4); 136 } 137 case 5 -> { 138 System.out.println("请修改:"); 139 String n5 = sc.next(); 140 warehouse2[0].setWarehousenumber(n5); 141 } 142 case 6 -> { 143 System.out.println("请修改:"); 144 String n6 = sc.next(); 145 warehouse2[0].setWarehouseplace(n6); 146 } 147 case 7 -> { 148 System.out.println("请修改:"); 149 int n7 = sc.nextInt(); 150 warehouse2[0].setItemnumber(n7); 151 } 152 default -> { 153 System.out.println("该选项不存在,请重新输入"); 154 } 155 } 156 157 } 158 //第三次分解 主界面方法: 159 public static void mainFrame(WarehouseInformation2[] warehouse2){ 160 Scanner sc = new Scanner(System.in); 161 while(true){ 162 System.out.println("***********************************************************"); 163 System.out.println(" 石家庄铁道大学前进22软件开发有限公司"); 164 System.out.println(" 仓库管理系统2022版"); 165 System.out.println("***********************************************************"); 166 System.out.println(" 1、商品入库管理"); 167 System.out.println(" 2、商品信息修改"); 168 System.out.println(" 3、商品出库管理"); 169 System.out.println(" 4、仓库盘点管理"); 170 System.out.println("***********************************************************"); 171 System.out.println(" 请选择:"); 172 int choose = sc.nextInt(); 173 switch(choose){ 174 case 1 -> goodsWarehousing(warehouse2); //第三次分解 商品入库方法 175 case 2 -> modifyWarehouse(warehouse2); //第三次分解 商品修改方法 176 case 3 -> outboundWarehouse(warehouse2); //第三次分解 商品出库方法 177 case 4 -> countGoods(warehouse2); //第三次分解 统计商品库存数量方法 178 default -> { 179 System.out.println("该选项不存在,请重新输入"); 180 break; 181 } 182 } 183 } 184 } 185 186 //第三次分解 商品入库方法: 187 public static void goodsWarehousing(WarehouseInformation2[] warehouse2){ 188 Scanner sc = new Scanner(System.in); 189 //第二次分解 新增数据: 190 addData(warehouse2); 191 192 193 System.out.println("***********************************************************"); 194 System.out.println(" 石家庄铁道大学前进22软件开发有限公司"); 195 System.out.println(" 仓库管理系统2022版"); 196 System.out.println("***********************************************************"); 197 System.out.println(" 商品编号:" + warehouse2[0].getItemno()); 198 System.out.println(" 商品名称:" + warehouse2[0].getItemname()); 199 System.out.println(" 供货商信息:" + warehouse2[0].getSuppliername()); 200 System.out.println(" 入库时间:" + warehouse2[0].getWarehousingtime()); 201 System.out.println(" 存放仓库号:" + warehouse2[0].getWarehousenumber()); 202 System.out.println(" 存放位置信息:" + warehouse2[0].getWarehouseplace()); 203 System.out.println(" 入库商品数量:" + warehouse2[0].getItemnumber()); 204 System.out.println(" 该商品入库操作已完成,是否提交(Y/N)"); 205 System.out.println("**********************************************************"); 206 String choose2 = sc.next(); 207 if(choose2.equals("N")) { 208 warehouse2[0] = null; 209 210 } 211 // else if(choose2.equals("Y")){ 212 // addData(warehouse2); 213 //214 // } 215 216 } 217 218 //第三次分解 商品修改方法: 219 public static void modifyWarehouse(WarehouseInformation2[] warehouse2){ 220 System.out.println("***********************************************************"); 221 System.out.println(" 石家庄铁道大学前进22软件开发有限公司"); 222 System.out.println(" 仓库管理系统2022版"); 223 System.out.println("***********************************************************"); 224 System.out.println(" 请输入商品编号:XXXXXXXX"); 225 System.out.println("***********************************************************"); 226 227 modifyData(warehouse2); 228 } 229 //第三次分解 商品出库方法: 230 public static void outboundWarehouse(WarehouseInformation2[] warehouse2){ 231 Scanner sc = new Scanner(System.in); 232 233 big:while(true){ 234 System.out.println("请输入商品编号:"); 235 String n2number = sc.next(); 236 for (int m = 0; m < warehouse2.length; m++) { 237 if (warehouse2[m].getItemno().equals(n2number)) { 238 System.out.println("***********************************************************"); 239 System.out.println(" 商品编号:" + warehouse2[0].getItemno()); 240 System.out.println(" 商品名称:" + warehouse2[0].getItemname()); 241 System.out.println(" 供货商信息:" + warehouse2[0].getSuppliername()); 242 System.out.println(" 入库时间:" + warehouse2[0].getWarehousingtime()); 243 System.out.println(" 存放仓库号:" + warehouse2[0].getWarehousenumber()); 244 System.out.println(" 存放位置信息:" + warehouse2[0].getWarehouseplace()); 245 System.out.println("**********************************************************"); 246 int num; 247 while(true){ 248 System.out.println("请输入出库数量:"); 249 num = sc.nextInt(); 250 if(num <= warehouse2[0].getItemnumber()){ 251 break; 252 }else{ 253 System.out.println("出库数量错误!"); 254 } 255 } 256 countWarehouse(num,warehouse2); 257 break big; 258 } else { 259 System.out.println("商品不存在,请重新输入"); 260 } 261 } 262 } 263 264 } 265 //第三次分解 统计商品库存数量方法: 266 public static void countGoods(WarehouseInformation2[] warehouse2){ 267 //要完成(1)的总数,感觉应该在入库时,添加判断存在信息,直接添加入库数量 268 System.out.println("商品编号:" + warehouse2[0].getItemno() + "、商品名称:" + warehouse2[0].getItemname() + "、库存数量:" + warehouse2[0].getItemnumber()); 269 } 270 //格式判断: 271 public static boolean geshi(String str){ 272 //判断录入字符是否为3/8个 273 if(str.length() != 8 && str.length() !=3){ 274 return false; 275 }else{ 276 //判断录入格式是否为数字 277 for (int i = 0; i < str.length(); i++) { 278 if(!(str.charAt(i)<='9' && str.charAt(i)>= '0')){ 279 return false; 280 } 281 } 282 } 283 return true; 284 } 285 //根据商品编号显示库存数量 286 public static void countWarehouse(int num, WarehouseInformation2[] warehouse2){ 287 int snum = 0; 288 snum = warehouse2[0].getItemnumber() - num; 289 System.out.println("剩余库存数为:" + snum); 290 warehouse2[0].setItemnumber(snum); 291 } 292 }
*****************************************************************************************************************************************************************************************
1 //第一次分解 数据类: 2 public class WarehouseInformation2 { 3 private String itemno; 4 private String itemname; 5 private String suppliername; 6 private String warehousingtime; 7 private String shipmenttime; 8 private String warehousenumber; 9 private String warehouseplace; 10 private int itemnumber; 11 private int outnumber; 12 13 public WarehouseInformation2() { 14 } 15 16 public WarehouseInformation2(String itemno, String itemname, String suppliername, String warehousingtime, String warehousenumber, String shipmenttime, String warehouseplace, int itemnumber, int outnumber) { 17 this.itemno = itemno; 18 this.itemname = itemname; 19 this.suppliername = suppliername; 20 this.warehousingtime = warehousingtime; 21 this.shipmenttime = shipmenttime; 22 this.warehousenumber = warehousenumber; 23 this.warehouseplace = warehouseplace; 24 this.itemnumber = itemnumber; 25 this.outnumber = outnumber; 26 } 27 28 public String getItemno() { 29 return itemno; 30 } 31 32 public void setItemno(String itemno) { 33 this.itemno = itemno; 34 } 35 36 public String getItemname() { 37 return itemname; 38 } 39 40 public void setItemname(String itemname) { 41 this.itemname = itemname; 42 } 43 44 public String getSuppliername() { 45 return suppliername; 46 } 47 48 public void setSuppliername(String suppliername) { 49 this.suppliername = suppliername; 50 } 51 52 public String getWarehousingtime() { 53 return warehousingtime; 54 } 55 56 public void setWarehousingtime(String warehousingtime) { 57 this.warehousingtime = warehousingtime; 58 } 59 60 public String getShipmenttime() { 61 return shipmenttime; 62 } 63 64 public void setShipmenttime(String shipmenttime) { 65 this.shipmenttime = shipmenttime; 66 } 67 68 public String getWarehousenumber() { 69 return warehousenumber; 70 } 71 72 public void setWarehousenumber(String warehousenumber) { 73 this.warehousenumber = warehousenumber; 74 } 75 76 public String getWarehouseplace() { 77 return warehouseplace; 78 } 79 80 public void setWarehouseplace(String warehouseplace) { 81 this.warehouseplace = warehouseplace; 82 } 83 84 public int getItemnumber() { 85 return itemnumber; 86 } 87 88 public void setItemnumber(int itemnumber) { 89 this.itemnumber = itemnumber; 90 } 91 92 public int getOutnumber() { 93 return outnumber; 94 } 95 96 public void setOutnumber(int outnumber) { 97 this.outnumber = outnumber; 98 } 99 }
本文来自博客园,作者:suN(小硕),转载请注明原文链接:https://www.cnblogs.com/liushuosbkd2003/p/17704860.html