5.13课后作业

public class WarehouseInformation {
private String itemno; //商品编号
private String itemname; //商品名称
private String suppliername; //供货商名称
private String warehousingtime; //入库时间
private String shipmenttime; //出库时间
private String warehousenumber; //仓库编号
private String warehouseplace; //存放商品的具体位置
private int itemnumber; //入库商品的数量
private int outnumber; //出库商品的数量

public String getItemno() {
return itemno;
}

public void setItemno(String itemno) {
this.itemno = itemno;
}

public String getItemname() {
return itemname;
}

public void setItemname(String itemname) {
this.itemname = itemname;
}

public String getSuppliername() {
return suppliername;
}

public void setSuppliername(String suppliername) {
this.suppliername = suppliername;
}

public String getWarehousingtime() {
return warehousingtime;
}

public void setWarehousingtime(String warehousingtime) {
this.warehousingtime = warehousingtime;
}

public String getShipmenttime() {
return shipmenttime;
}

public void setShipmenttime(String shipmenttime) {
this.shipmenttime = shipmenttime;
}

public String getWarehousenumber() {
return warehousenumber;
}

public void setWarehousenumber(String warehousenumber) {
this.warehousenumber = warehousenumber;
}

public String getWarehouseplace() {
return warehouseplace;
}

public void setWarehouseplace(String warehouseplace) {
this.warehouseplace = warehouseplace;
}

public int getItemnumber() {
return itemnumber;
}

public void setItemnumber(int itemnumber) {
this.itemnumber = itemnumber;
}

public int getOutnumber() {
return outnumber;
}

public void setOutnumber(int outnumber) {
this.outnumber = outnumber;
}

public void setInitialValues(String itemno, String itemname, String suppliername, String warehousingtime, String shipmenttime, String warehousenumber, String warehouseplace, int itemnumber, int outnumber) {
this.itemno = itemno;
this.itemname = itemname;
this.suppliername = suppliername;
this.warehousingtime = warehousingtime;
this.shipmenttime = shipmenttime;
this.warehousenumber = warehousenumber;
this.warehouseplace = warehouseplace;
this.itemnumber = itemnumber;
this.outnumber = outnumber;
}
}

import java.util.Scanner;
public class WarehouseManagement {

 

static int nnum=0;

public static void main(String[] args) {

WarehouseInformation[] warehouseInformations=new WarehouseInformation[5];
WarehouseInformation warehouseInformation1=new WarehouseInformation();
warehouseInformation1.setItemno("20224085");
warehouseInformation1.setItemname("华为笔记本电脑");
warehouseInformation1.setSuppliername("河北省正大光明有限公司");
warehouseInformation1.setWarehousenumber("003");
warehouseInformation1.setWarehouseplace("0180350");
warehouseInformation1.setItemnumber(100);
warehouseInformation1.setOutnumber(0);

WarehouseInformation warehouseInformation2 = new WarehouseInformation();
warehouseInformation2.setItemno("20224086");
warehouseInformation2.setItemname("Apple iPhone");
warehouseInformation2.setSuppliername("Guangdong Xinrui Technology Co., Ltd.");
warehouseInformation2.setWarehousenumber("004");
warehouseInformation2.setWarehouseplace("0180351");
warehouseInformation2.setItemnumber(50);
warehouseInformation2.setOutnumber(10);

WarehouseInformation warehouseInformation3 = new WarehouseInformation();
warehouseInformation3.setItemno("20224087");
warehouseInformation3.setItemname("Samsung Tablet");
warehouseInformation3.setSuppliername("Shanghai Letian Electronics Co., Ltd.");
warehouseInformation3.setWarehousenumber("005");
warehouseInformation3.setWarehouseplace("0180352");
warehouseInformation3.setItemnumber(80);
warehouseInformation3.setOutnumber(20);

WarehouseInformation warehouseInformation4 = new WarehouseInformation();
warehouseInformation4.setItemno("20224088");
warehouseInformation4.setItemname("Huawei Smartphone");
warehouseInformation4.setSuppliername("Beijing Zhongxing Technology Co., Ltd.");
warehouseInformation4.setWarehousenumber("006");
warehouseInformation4.setWarehouseplace("0180353");
warehouseInformation4.setItemnumber(120);
warehouseInformation4.setOutnumber(50);

WarehouseInformation warehouseInformation5 = new WarehouseInformation();
warehouseInformation5.setItemno("20224089");
warehouseInformation5.setItemname("Xiaomi TV");
warehouseInformation5.setSuppliername("Zhejiang Rongyao Electronics Co., Ltd.");
warehouseInformation5.setWarehousenumber("007");
warehouseInformation5.setWarehouseplace("0180354");
warehouseInformation5.setItemnumber(60);
warehouseInformation5.setOutnumber(30);
warehouseInformations[0]=warehouseInformation1;
warehouseInformations[1]=warehouseInformation2;
warehouseInformations[2]=warehouseInformation3;
warehouseInformations[3]=warehouseInformation4;
warehouseInformations[4]=warehouseInformation5;

 

Scanner scanner=new Scanner(System.in);
while (true){
pzmu();
System.out.println("请输入数字选择功能:");
int option=scanner.nextInt();
if(option==1){
addcommodity(warehouseInformations,scanner);
}
else if(option==2){
changemod(warehouseInformations,scanner);
}
else if(option==3){
ckmannger(warehouseInformations,scanner);
}
else if(option==4){
showgoods(warehouseInformations);
}
else{
System.out.println("该选项不存在");
}
}

}


private static void showgoods(WarehouseInformation[] warehouseInformations) {
pzno();
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("………………………………………………….");

System.out.println("**********************************************************");

}

private static void ckmannger(WarehouseInformation[] warehouseInformations, Scanner scanner) {
pzno();
String is=new String(); //可能出错
System.out.println("请输入商品编号:");
String itemno=scanner.next();
WarehouseInformation warehouseInformation=findmod(warehouseInformations,itemno);
if(warehouseInformation==null){
System.out.println("库中没有该商品");
return;
}
System.out.println("1.商品编号:"+warehouseInformation.getItemno());
System.out.println("2.商品名称:"+warehouseInformation.getItemname());
System.out.println("3.供货商信息:"+warehouseInformation.getSuppliername());
System.out.println("4.入库时间:"+warehouseInformation.getWarehousingtime());
System.out.println("5.存放仓库号:"+warehouseInformation.getWarehousenumber());
System.out.println("6.存放位置信息:"+warehouseInformation.getWarehouseplace());
System.out.println("7.入库商品数量:"+warehouseInformation.getItemnumber());

System.out.println("请输入出库时间:");
String outtime=scanner.next();
System.out.println("请输入出库数量:");
int outnumber=scanner.nextInt();
if(outnumber>warehouseInformation.getItemnumber()){
System.out.println("超过入库数量!");
return;
}else {
System.out.println("是否保存(y/n):");
String ism=scanner.next();
if(ism.equalsIgnoreCase("Y")){
warehouseInformation.setOutnumber(outnumber);
warehouseInformation.setShipmenttime(outtime);
System.out.println("保存成功!");
return;
}
else{
return;
}
}
}

private static void changemod(WarehouseInformation[] warehouseInformations, Scanner scanner) {
while (true) {
pzno();
String is = new String(); //可能出错
System.out.println("请输入商品编号:");
String itemno = scanner.next();
WarehouseInformation warehouseInformation = findmod(warehouseInformations, itemno);
if (warehouseInformation == null) {
System.out.println("库中没有该商品");
continue;
}
System.out.println("1.商品编号:" + warehouseInformation.getItemno());
System.out.println("2.商品名称:" + warehouseInformation.getItemname());
System.out.println("3.供货商信息:" + warehouseInformation.getSuppliername());
System.out.println("4.入库时间:" + warehouseInformation.getWarehousingtime());
System.out.println("5.存放仓库号:" + warehouseInformation.getWarehousenumber());
System.out.println("6.存放位置信息:" + warehouseInformation.getWarehouseplace());
System.out.println("7.入库商品数量:" + warehouseInformation.getItemnumber());
System.out.println("请选择需要修改的信息编号(1-7):");
int judge = scanner.nextInt();
if (judge == 1) {
System.out.println("请输入修改后的商品编号");
String no = scanner.next();
System.out.println("是否保存(y/n):");
is = scanner.next();
if (is.equalsIgnoreCase("Y")) {
warehouseInformation.setItemno(no);
System.out.println("保存成功!");
return;
} else {
return;
}
}
if (judge == 2) {
System.out.println("请输入修改后的商品名称:");
String mname = scanner.next();
System.out.println("是否保存(y/n):");
is = scanner.next();
if (is.equalsIgnoreCase("Y")) {
warehouseInformation.setItemname(mname);
System.out.println("保存成功!");
return;
} else {
return;
}
}
if (judge == 3) {
System.out.println("请输入修改后的供货商信息:");
String supname = scanner.next();
System.out.println("是否保存(y/n):");
is = scanner.next();
if (is.equalsIgnoreCase("Y")) {
warehouseInformation.setSuppliername(supname);
System.out.println("保存成功!");
return;
} else {
return;
}
}
if (judge == 4) {
System.out.println("请输入修改后的入库时间:");
String intime = scanner.next();
System.out.println("是否保存(y/n):");
is = scanner.next();
if (is.equalsIgnoreCase("Y")) {
warehouseInformation.setWarehousingtime(intime);
System.out.println("保存成功!");
return;
} else {
return;
}
}
if (judge == 5) {
System.out.println("请输入修改后的存放仓库号:");
String hosenumber = scanner.next();
System.out.println("是否保存(y/n):");
is = scanner.next();
if (is.equalsIgnoreCase("Y")) {
warehouseInformation.setWarehousenumber(hosenumber);
System.out.println("保存成功!");
return;
} else {
return;
}
}
if (judge == 6) {
System.out.println("请输入修改后的存放位置信息:");
String place = scanner.next();
System.out.println("是否保存(y/n):");
is = scanner.next();
if (is.equalsIgnoreCase("Y")) {
warehouseInformation.setWarehouseplace(place);
System.out.println("保存成功!");
return;
} else {
return;
}
}
if (judge == 7) {
System.out.println("请输入修改后的商品数量:");
int num = scanner.nextInt();
System.out.println("是否保存(y/n):");
is = scanner.next();
if (is.equalsIgnoreCase("Y")) {
warehouseInformation.setItemnumber(num);
System.out.println("保存成功!");
return;
} else {
System.out.println("该选项不存在!");
return;
}
}
}
}

public static void addcommodity(WarehouseInformation[] warehouseInformations, Scanner scanner) {
while (true) {
pzno();
WarehouseInformation warehouseInformation = new WarehouseInformation();
System.out.println("请输入商品编码:");
String confirm1 = scanner.next();
if (confirm1.length() != 8) {
System.out.println("录入错误");
return;
} else {
warehouseInformation.setItemno(confirm1);
}
System.out.println("请输入商品名称:");
String confirm2 = scanner.next();
warehouseInformation.setItemname(confirm2);
System.out.println("请输入供货商信息:");
String confirm3 = scanner.next();
warehouseInformation.setSuppliername(confirm3);
System.out.println("入库时间:");
String confirm4 = scanner.next();
if (confirm4.length() != 8) {
System.out.println("录入错误");
return;
} else {
warehouseInformation.setWarehousingtime(confirm4);
}
System.out.println("请输入存放仓库号:");
String confirm5 = scanner.next();
if (confirm5.length() != 3) {
System.out.println("录入错误");
return;
} else {
warehouseInformation.setWarehousenumber(confirm5);
}
System.out.println("请输入存放位置信息:");
String confirm6 = scanner.next();
warehouseInformation.setWarehouseplace(confirm6);

pzno();
System.out.println("1.商品编号:" + warehouseInformation.getItemno());
System.out.println("2.商品名称:" + warehouseInformation.getItemname());
System.out.println("3.供货商信息:" + warehouseInformation.getSuppliername());
System.out.println("4.入库时间:" + warehouseInformation.getWarehousingtime());
System.out.println("5.存放仓库号:" + warehouseInformation.getWarehousenumber());
System.out.println("6.存放位置信息:" + warehouseInformation.getWarehouseplace());
System.out.println("7.入库商品数量:" + warehouseInformation.getItemnumber());
System.out.println("该商品入库操作已完成,是否提交(Y/N)");
String tj = scanner.next();
if (tj.equalsIgnoreCase("Y")) {
warehouseInformations[nnum] = warehouseInformation;
nnum++;
System.out.println("提交成功!");
break;
} else
continue;

}

}

public static void pzno(){
System.out.println("***********************************************************");
System.out.println(" 石家庄铁道大学前进22软件开发有限公司");
System.out.println(" 仓库管理系统2022版");
System.out.println("***********************************************************");
}


public static void pzmu(){
System.out.println("***********************************************************");
System.out.println(" 石家庄铁道大学前进22软件开发有限公司");
System.out.println(" 仓库管理系统2022版");
System.out.println(" 1、商品入库管理");
System.out.println(" 2、商品信息修改");
System.out.println(" 3、商品出库管理");
System.out.println(" 4、仓库盘点管理");
System.out.println("***********************************************************");
}


public static WarehouseInformation findmod(WarehouseInformation[] warehouseInformations,String itrmno){
for(int i=0;i<warehouseInformations.length;i++){
if(warehouseInformations[i].getItemno().equals(itrmno)&&warehouseInformations[i]!=null){
return warehouseInformations[i];
}
}
return null;
}

 

 

 

 

 

 

}

posted @ 2024-05-13 21:21  catsahsy  阅读(4)  评论(0编辑  收藏  举报