开学测试代码

import jdk.dynalink.beans.StaticClass;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import java.util.Scanner;

public class WarehouseManagement {
static WarehouseInformation[] warehouseInformations=new WarehouseInformation[50];

public void add(){

}
public void chishihua(){
WarehouseInformation w1=new WarehouseInformation("00000001","商品名称1","供货商名称1","20220901","20220902","001","00010101",176,100);
WarehouseInformation w2=new WarehouseInformation("00000002","商品名称2","供货商名称2","20220901","20220903","002","00020202",187,100);
WarehouseInformation w3=new WarehouseInformation("00000003","商品名称3","供货商名称3","20220901","20220904","003","00030303",450,200);
WarehouseInformation w4=new WarehouseInformation("00000005","商品名称4","供货商名称4","20220902","20220904","004","00040404",310,200);
WarehouseInformation w5=new WarehouseInformation("00000005","商品名称5","供货商名称5","20220902","20220905","005","00050505",500,400);
warehouseInformations[0]=w1;
warehouseInformations[1]=w2;
warehouseInformations[2]=w3;
warehouseInformations[3]=w4;
warehouseInformations[4]=w5;
}

public void mainFrame( ){
System.out.println("***********************************************************\n");
System.out.println(" 石家庄铁道大学前进22软件开发有限公司\n");
System.out.println(" 仓库管理系统2022版\n");
System.out.println("***********************************************************\n");
System.out.println(" 1、商品入库管理\n");
System.out.println(" 2、商品信息修改\n");
System.out.println(" 3、商品出库管理\n");
System.out.println(" 4、仓库盘点管理\n");
System.out.println("**********************************************************\n");
System.out.println("请选择您需要的功能:\n");
choice();
}

public void choice(){
Scanner sc=new Scanner(System.in);
int c=sc.nextInt();
switch (c){
case 1:
goodsWarehousing();
break;
case 2:
modifyWarehouse ();
break;
case 3:
outboundWarehouse();
break;
case 4:
countGoods();
break;
default:
System.out.println("您输入的信息有误请再次输入");
mainFrame( );
}
}
//商品入库管理方法
public void goodsWarehousing(){
System.out.println("***********************************************************\n");
System.out.println(" 石家庄铁道大学前进22软件开发有限公司\n");
System.out.println(" 仓库管理系统2022版\n");
System.out.println("***********************************************************\n");
WarehouseInformation item =new WarehouseInformation();
Scanner scanner = new Scanner(System.in);

// 商品编号输入验证
while (true) {
System.out.println("商品编号:");
String itemNo = scanner.nextLine();
if (itemNo.matches("\\d{8}")) {
item.setItemno(itemNo);
break;
} else {
System.out.println("商品编号格式错误,请重新输入。");
}
}

System.out.println("商品名称:");
item.setItemname(scanner.nextLine());
System.out.print("供货商信息:");
item.setSuppliername(scanner.nextLine());

// 入库时间输入验证
while (true) {
System.out.println("入库时间:");
String warehousingTime = scanner.nextLine();
if (warehousingTime.matches("\\d{8}")) {
item.setWarehousingtime(warehousingTime);
break;
} else {
System.out.println("入库时间格式错误,请重新输入。");
}
}

// 存放仓库号输入验证
while (true) {
System.out.println("存放仓库号:");
String warehouseNumber = scanner.nextLine();
if (warehouseNumber.matches("\\d{3}")) {
item.setWarehousenumber(warehouseNumber);
break;
} else {
System.out.println("存放仓库号格式错误,请重新输入。");
}
}

// 存放位置信息输入验证
while (true) {
System.out.println("存放位置信息:");
String warehousePlace = scanner.nextLine();
if (warehousePlace.matches("\\d{8}")) {
item.setWarehouseplace(warehousePlace);
break;
} else {
System.out.println("存放位置信息格式错误,请重新输入。");
}
}

// 入库数量输入验证
while (true) {
System.out.println("入库商品数量:");
int itemNumber = scanner.nextInt();
scanner.nextLine();
if (itemNumber > 0) {
item.setItemnumber(itemNumber);
break;
} else {
System.out.println("入库商品数量应大于0,请重新输入。");
}
}

System.out.println("***********************************************************");
System.out.println("石家庄铁道大学前进22软件开发有限公司");
System.out.println("仓库管理系统2022版");
System.out.println("***********************************************************");
System.out.println("商品编号:" + item.getItemno());
System.out.println("商品名称:" + item.getItemname());
System.out.println("供货商信息:" + item.getSuppliername());
System.out.println("入库时间:" + item.getWarehousingtime());
System.out.println("存放仓库号:" + item.getWarehousenumber());
System.out.println("存放位置信息:" + item.getWarehouseplace());
System.out.println("入库商品数量:" + item.getItemnumber());
System.out.println("***********************************************************");
System.out.print("该商品入库操作已完成,是否提交(Y/N):");
String choice = scanner.nextLine();
if (choice.equals("Y")) {
// 将商品信息存储到相应的数组中
for (int i = 0; i < warehouseInformations.length; i++) {
if (warehouseInformations[i] == null) {
warehouseInformations[i] = item;
break;
}
else{
break;
}
}
}
}

//商品信息修改方法
public void modifyWarehouse (){
while (true) {
int t=0;
System.out.println("***********************************************************\n");
System.out.println(" 石家庄铁道大学前进22软件开发有限公司\n");
System.out.println(" 仓库管理系统2022版\n");
System.out.println("***********************************************************\n");
System.out.println(" 请输入商品编号:XXXXXXXX\n");
System.out.println("***********************************************************\n");
System.out.println("请输入八位的商品编号:");
Scanner sc =new Scanner(System.in);
String num =sc.next();
for(int i=0;i<50;i++){
if (num.equals(warehouseInformations[i].getItemno())){
System.out.println("***********************************************************\n");
System.out.println(" 石家庄铁道大学前进22软件开发有限公司\n");
System.out.println(" 仓库管理系统2022版\n");
System.out.println("***********************************************************\n");
System.out.println(" 1.商品编号:"+warehouseInformations[i].getItemno());
System.out.println(" 2.商品名称:"+warehouseInformations[i].getItemname());
System.out.println(" 3.供货商信息:"+warehouseInformations[i].getSuppliername());
System.out.println(" 4.入库时间:"+warehouseInformations[i].getWarehousingtime());
System.out.println(" 5.存放仓库号:"+warehouseInformations[i].getWarehousenumber());
System.out.println(" 6.存放位置信息:"+warehouseInformations[i].getWarehouseplace());
System.out.println(" 7.入库商品数量:"+warehouseInformations[i].getItemnumber());
System.out.println(" 请选择需要修改的信息编号(1-7):\n");
System.out.println("**********************************************************\n");
int cho= sc.nextInt();
if (cho>=1 && cho<=7){
System.out.println("***********************************************************\n");
System.out.println(" 石家庄铁道大学前进22软件开发有限公司\n");
System.out.println(" 仓库管理系统2022版\n");
System.out.println("***********************************************************\n");
System.out.println(" 1.商品编号:"+warehouseInformations[i].getItemno());
System.out.println(" 2.商品名称:"+warehouseInformations[i].getItemname());
System.out.println(" 3.供货商信息:"+warehouseInformations[i].getSuppliername());
System.out.println(" 4.入库时间:"+warehouseInformations[i].getWarehousingtime());
System.out.println(" 5.存放仓库号:"+warehouseInformations[i].getWarehousenumber());
System.out.println(" 6.存放位置信息:"+warehouseInformations[i].getWarehouseplace());
System.out.println(" 7.入库商品数量:"+warehouseInformations[i].getItemnumber());
System.out.println(" 请选择需要修改的信息编号(1-7):"+cho);
System.out.println(" 请输入修改后的商品信息:XXXXXXXX\n");
System.out.println("**********************************************************\n");
switch (cho){
case 1:
String n1=sc.next();
String t1=warehouseInformations[i].getItemno();
warehouseInformations[i].setItemno(n1);
System.out.println("信息修改完毕,是否保存(Y/N)\n");
String c1=sc.next();
if(c1.equals("Y")){
t=1;
mainFrame( );

}else if(c1.equals("N")) {
t = 0;
warehouseInformations[i].setItemno(t1);

}
break;
case 2:
String n2 = sc.next();
String t2=warehouseInformations[i].getItemname();
warehouseInformations[i].setItemname(n2);
System.out.println("信息修改完毕,是否保存(Y/N)\n");
String c2=sc.next();
if(c2.equals("Y")){
t=1;
mainFrame( );

}else if(c2.equals("N")) {
t = 0;
warehouseInformations[i].setItemname(t2);
}
break;
case 3:
String n3= sc.next();
String t3=warehouseInformations[i].getSuppliername();
warehouseInformations[i].setSuppliername(n3);
System.out.println("信息修改完毕,是否保存(Y/N)\n");
String c3=sc.next();
if(c3.equals("Y")){
t=1;
mainFrame( );

}else if(c3.equals("N")) {
t = 0;
warehouseInformations[i].setSuppliername(t3);
}
break;
case 4:
String n4 = sc.next();
String t4 =warehouseInformations[i].getWarehousingtime();
warehouseInformations[i].setWarehousingtime(n4);
System.out.println("信息修改完毕,是否保存(Y/N)\n");
String c4=sc.next();
if(c4.equals("Y")){
t=1;
mainFrame( );
}else if(c4.equals("N")) {
t = 0;
warehouseInformations[i].setWarehousingtime(t4);

}
break;
case 5:
String n5= sc.next();
String t5=warehouseInformations[i].getWarehousenumber();
warehouseInformations[i].setWarehousenumber(n5);
System.out.println("信息修改完毕,是否保存(Y/N)\n");
String c5=sc.next();
if(c5.equals("Y")){
t=1;
mainFrame( );

}else if(c5.equals("N")) {
t = 0;
warehouseInformations[i].setWarehousenumber(t5);
}
break;
case 6:
String n6 = sc.next();
String t6=warehouseInformations[i].getWarehouseplace();
warehouseInformations[i].setWarehouseplace(n6);
System.out.println("信息修改完毕,是否保存(Y/N)\n");
String c6=sc.next();
if(c6.equals("Y")){
t=1;
mainFrame( );

}else if(c6.equals("N")) {
t = 0;
warehouseInformations[i].setWarehouseplace(t6);
}
break;
case 7:
int n7=sc.nextInt();
int t7=warehouseInformations[i].getItemnumber();
warehouseInformations[i].setItemnumber(n7);
System.out.println("信息修改完毕,是否保存(Y/N)\n");
String c7=sc.next();
if(c7.equals("Y")){
t=1;
mainFrame( );

}else if(c7.equals("N")) {
t = 0;
warehouseInformations[i].setItemnumber(t7);
}
break;
}

}else {
System.out.println("错误信息(该选项不存在)\n");
t=1;
mainFrame( );
}
break;
}else{
t=1;
System.out.println("库中不存在该商品信息\n");
}
}
if(t==1){
mainFrame( );
break;
}
}
}

//商品出库管理方法
public void outboundWarehouse() {
while (true) {
int t;
t = 0;
System.out.println("***********************************************************\n");
System.out.println(" 石家庄铁道大学前进22软件开发有限公司\n");
System.out.println(" 仓库管理系统2022版\n");
System.out.println("***********************************************************\n");
System.out.println(" 请输入商品编号:XXXXXXXX\n");
System.out.println("***********************************************************\n");
System.out.println("请输入八位的商品编号:");
Scanner sc = new Scanner(System.in);
String num = sc.next();
for (int i = 0; i < 50; i++) {
if (num.equals(warehouseInformations[i].getItemno())) {
System.out.println("***********************************************************\n");
System.out.println(" 石家庄铁道大学前进22软件开发有限公司\n");
System.out.println(" 仓库管理系统2022版\n");
System.out.println("***********************************************************\n");
System.out.println(" 1.商品编号:" + warehouseInformations[i].getItemno());
System.out.println(" 2.商品名称:" + warehouseInformations[i].getItemname());
System.out.println(" 3.供货商信息:" + warehouseInformations[i].getSuppliername());
System.out.println(" 4.入库时间:" + warehouseInformations[i].getWarehousingtime());
System.out.println(" 5.存放仓库号:" + warehouseInformations[i].getWarehousenumber());
System.out.println(" 6.存放位置信息:" + warehouseInformations[i].getWarehouseplace());
System.out.println(" 7.入库商品数量:" + warehouseInformations[i].getItemnumber());
System.out.println(" 出库时间:XXXXXXXXX\n");
System.out.println(" 出库数量:xxx\n");
System.out.println("**********************************************************\n");
System.out.println("请依次填写出库时间和出库数量(其中出库时间为八位,出库数量要小于该商品在数据库中所有入库数量之和):\n");
String ti= sc.next();
int ni=sc.nextInt();
boolean isDate1Earlier = compareDates(warehouseInformations[i].getShipmenttime(), ti) <= 0;
boolean isDate2Later = compareDates(warehouseInformations[i].getShipmenttime(), ti) > 0;

if (isDate1Earlier && (ni<=warehouseInformations[i].getItemnumber()) ) {
System.out.println(" 是否保存以上操作(Y/N)\n");
String cho = sc.next();
if(cho.equals("Y")){
warehouseInformations[i].setShipmenttime(ti);
warehouseInformations[i].setOutnumber(ni);
mainFrame( );
} else if (cho.equals("N")) {
mainFrame( );
}
} else if (isDate2Later || (ni>warehouseInformations[i].getItemnumber())) {
t=0;
System.out.println("出库时间不正确或出库数量不正确,请重新输入");

}
} else if(!num.equals(warehouseInformations[i].getItemno())) {
t = 1;
System.out.println("库中不存在该商品信息\n");
modifyWarehouse ();
}
}
if (t == 1) {
mainFrame( );
break;
}
}
}

 

//仓库盘点管理方法
public void countGoods(){
System.out.println("***********************************************************\n");
System.out.println(" 石家庄铁道大学前进22软件开发有限公司\n");
System.out.println(" 仓库管理系统2022版\n");
System.out.println("***********************************************************\n");
for (int i=0;i<=warehouseInformations.length;i++) {
System.out.println(i+1+"、"+" 商品编号:"+warehouseInformations[i].getItemno()+"、商品名称:"+warehouseInformations[i].getItemname()+"、库存数量:"+(warehouseInformations[i].getItemnumber()-warehouseInformations[i].getOutnumber()));
}
System.out.println("**********************************************************\n");

}


//比较出库时间的大小
private static int compareDates(String date1, String date2) {
DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");

try {
Date d1 = dateFormat.parse(date1);
Date d2 = dateFormat.parse(date2);
return d1.compareTo(d2);
} catch (ParseException e) {
e.printStackTrace();
return 0;
}

}

public static void main(String[] args) {
WarehouseManagement Wh1= new WarehouseManagement();
Wh1.chishihua();
Wh1.mainFrame();
}

}

posted @ 2023-09-17 19:40  不会JAVA的小袁  阅读(5)  评论(0编辑  收藏  举报