测验修改
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 WarehouseInformation() {
}
public WarehouseInformation(String itemno, String itemname, String suppliername, String warehousingtime, String warehousenumber, String shipmenttime, 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;
}
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;
}
import java.util.Scanner;
public class Java1717 {
public class WarehouseManagement2 {
public static void main(String[] args) {
// 仓库信息:
WarehouseInformation[] warehouse2= new WarehouseInformation[20];
warehouse2[0] = new WarehouseInformation();
// 主界面方法:
mainFrame(warehouse2);
}
//工具类方法定义
// 新增数据:
public static void addData(WarehouseInformation[] warehouse2){
// 暂未解决: 新增数据的 “下一条” 问题
Scanner sc = new Scanner(System.in);
while(true){
System.out.println("请录入商品编号:");
String sitemno = sc.next();
boolean b1 = geshi(sitemno); //判断格式是否正确
if(b1){
warehouse2[0].setItemno(sitemno); //商品编号
break;
}else{
System.out.println("格式错误,请重新录入");
}
}
// sout(arr); //我对自己的想法进行保留,但是代码忘记多不多了,也懒得弄了
//sout()之前是一个界面输出的方法
System.out.println("请录入商品名称:");
String itemname = sc.next();
warehouse2[0].setItemname(itemname); //商品名称
// sout(arr);
System.out.println("请录入供货商信息:");
String suppliername = sc.next(); //供货商信息
warehouse2[0].setSuppliername(suppliername);
// sout(arr);
while(true){
System.out.println("请录入入库时间:");
String warehousingtime = sc.next(); //入库时间
boolean b2 = geshi(warehousingtime); //判断格式是否正确
if(b2){
warehouse2[0].setWarehousingtime(warehousingtime);
break;
}else{
System.out.println("格式错误,请重新录入");
}
}
while(true){
System.out.println("请录入存放仓库号:");
String warehousenumber = sc.next(); //仓库编号
boolean b3 = geshi(warehousenumber);
if(b3){
warehouse2[0].setWarehousenumber(warehousenumber);
break;
}else{
System.out.println("格式错误,请重新录入");
}
}
while(true){
System.out.println("请录入商品存放位置信息:");
String warehouseplace = sc.next(); //商品位置信息
boolean b = geshi(warehouseplace); //判断格式是否正确
if (b) {
warehouse2[0].setWarehouseplace(warehouseplace);
break;
} else {
System.out.println("格式错误,请重新录入");
}
}
System.out.println("请录入商品入库数量:");
int itemnumber = sc.nextInt(); //入库数量
warehouse2[0].setItemnumber(itemnumber);
}
// 数据修改:
public static void modifyData(WarehouseInformation[] warehouse2){
Scanner sc = new Scanner(System.in);
bian:while(true) {
System.out.println("请输入(八位)商品编号:");
//可以加个判断语句,但是没要求,我也懒得加
String innumber = sc.next();
for (int i = 0; i < warehouse2.length; i++) {
if (warehouse2[i].getItemno().equals(innumber)) {
System.out.println("***********************************************************");
System.out.println(" 石家庄铁道大学前进22软件开发有限公司");
System.out.println(" 仓库管理系统2022版");
System.out.println("***********************************************************");
System.out.println(" 1、商品编号:" + warehouse2[0].getItemno());
System.out.println(" 2、商品名称:" + warehouse2[0].getItemname());
System.out.println(" 3、供货商信息:" + warehouse2[0].getSuppliername());
System.out.println(" 4、入库时间:" + warehouse2[0].getWarehousingtime());
System.out.println(" 5、存放仓库号:" + warehouse2[0].getWarehousenumber());
System.out.println(" 6、存放位置信息:" + warehouse2[0].getWarehouseplace());
System.out.println(" 7、入库商品数量:" + warehouse2[0].getItemnumber());
System.out.println("**********************************************************");
System.out.println(" 请选择需要修改的内容:"); //choose3
break bian;
}
}
}
int choose3 = sc.nextInt();
switch (choose3) {
case 1 -> {
System.out.println("请修改:");
String n1 = sc.next();
warehouse2[0].setItemno(n1);
}
case 2 -> {
System.out.println("请修改:");
String n2 = sc.next();
warehouse2[0].setItemname(n2);
}
case 3 -> {
System.out.println("请修改:");
String n3 = sc.next();
warehouse2[0].setSuppliername(n3);
}
case 4 -> {
System.out.println("请修改:");
String n4 = sc.next();
warehouse2[0].setWarehousingtime(n4);
}
case 5 -> {
System.out.println("请修改:");
String n5 = sc.next();
warehouse2[0].setWarehousenumber(n5);
}
case 6 -> {
System.out.println("请修改:");
String n6 = sc.next();
warehouse2[0].setWarehouseplace(n6);
}
case 7 -> {
System.out.println("请修改:");
int n7 = sc.nextInt();
warehouse2[0].setItemnumber(n7);
}
default -> {
System.out.println("该选项不存在,请重新输入");
}
}
}
// 主界面方法:
public static void mainFrame(WarehouseInformation[] warehouse2){
Scanner sc = new Scanner(System.in);
while(true){
System.out.println("***********************************************************");
System.out.println(" 石家庄铁道大学前进22软件开发有限公司");
System.out.println(" 仓库管理系统2022版");
System.out.println("***********************************************************");
System.out.println(" 1、商品入库管理");
System.out.println(" 2、商品信息修改");
System.out.println(" 3、商品出库管理");
System.out.println(" 4、仓库盘点管理");
System.out.println("***********************************************************");
System.out.println(" 请选择:");
int choose = sc.nextInt();
switch(choose){
case 1 -> goodsWarehousing(warehouse2); // 商品入库
case 2 -> modifyWarehouse(warehouse2); // 商品修改
case 3 -> outboundWarehouse(warehouse2); // 商品出库
case 4 -> countGoods(warehouse2); // 统计商品库存数量
default -> {
System.out.println("该选项不存在,请重新输入");
break;
}
}
}
}
// 商品入库:
public static void goodsWarehousing(WarehouseInformation[] warehouse2){
Scanner sc = new Scanner(System.in);
// 新增数据:
addData(warehouse2);
System.out.println("***********************************************************");
System.out.println(" 石家庄铁道大学前进22软件开发有限公司");
System.out.println(" 仓库管理系统2022版");
System.out.println("***********************************************************");
System.out.println(" 商品编号:" + warehouse2[0].getItemno());
System.out.println(" 商品名称:" + warehouse2[0].getItemname());
System.out.println(" 供货商信息:" + warehouse2[0].getSuppliername());
System.out.println(" 入库时间:" + warehouse2[0].getWarehousingtime());
System.out.println(" 存放仓库号:" + warehouse2[0].getWarehousenumber());
System.out.println(" 存放位置信息:" + warehouse2[0].getWarehouseplace());
System.out.println(" 入库商品数量:" + warehouse2[0].getItemnumber());
System.out.println(" 该商品入库操作已完成,是否提交(Y/N)");
System.out.println("**********************************************************");
String choose2 = sc.next();
if(choose2.equals("N")) {
warehouse2[0] = null;
}
}
// 商品修改:
public static void modifyWarehouse(WarehouseInformation[] warehouse2){
System.out.println("***********************************************************");
System.out.println(" 石家庄铁道大学前进22软件开发有限公司");
System.out.println(" 仓库管理系统2022版");
System.out.println("***********************************************************");
System.out.println(" 请输入商品编号:XXXXXXXX");
System.out.println("***********************************************************");
modifyData(warehouse2);
}
// 商品出库:
public static void outboundWarehouse(WarehouseInformation[] warehouse2){
Scanner sc = new Scanner(System.in);
big:while(true){
System.out.println("请输入商品编号:");
String n2number = sc.next();
for (int m = 0; m < warehouse2.length; m++) {
if (warehouse2[m].getItemno().equals(n2number)) {
System.out.println("***********************************************************");
System.out.println(" 商品编号:" + warehouse2[0].getItemno());
System.out.println(" 商品名称:" + warehouse2[0].getItemname());
System.out.println(" 供货商信息:" + warehouse2[0].getSuppliername());
System.out.println(" 入库时间:" + warehouse2[0].getWarehousingtime());
System.out.println(" 存放仓库号:" + warehouse2[0].getWarehousenumber());
System.out.println(" 存放位置信息:" + warehouse2[0].getWarehouseplace());
System.out.println("**********************************************************");
int num;
while(true){
System.out.println("请输入出库数量:");
num = sc.nextInt();
if(num <= warehouse2[0].getItemnumber()){
break;
}else{
System.out.println("出库数量错误!");
}
}
countWarehouse(num,warehouse2);
break big;
} else {
System.out.println("商品不存在,请重新输入");
}
}
}
}
// 统计商品库存数量:
public static void countGoods(WarehouseInformation[] warehouse2){
System.out.println("商品编号:" + warehouse2[0].getItemno() + "、商品名称:" + warehouse2[0].getItemname() + "、库存数量:" + warehouse2[0].getItemnumber());
}
public static boolean geshi(String str){
if(str.length() != 8 && str.length() !=3){
return false;
}else{
//判断录入格式是否为数字
for (int i = 0; i < str.length(); i++) {
if(!(str.charAt(i)<='9' && str.charAt(i)>= '0')){
return false;
}
}
}
return true;
}
//根据商品编号显示库存数量
public static void countWarehouse(int num, WarehouseInformation[] warehouse2){
int snum = 0;
snum = warehouse2[0].getItemnumber() - num;
System.out.println("剩余库存数为:" + snum);
warehouse2[0].setItemnumber(snum);
}
}
}
public void setOutnumber(int outnumber) {
this.outnumber = outnumber;
}
}