首页 > 编程语言 >测试程序重写

测试程序重写

时间:2023-09-14 20:24:13浏览次数:34  
标签:String System 测试程序 sc println 重写 public out

import java.util.ArrayList;
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
ArrayList<WarehouseInformation> ware = new ArrayList<>();
while (true) {
show();
System.out.print("请输入数字:");
int choice = sc.nextInt();
switch (choice) {
case 1 -> addshop(ware);
case 2 -> setshop(ware);
case 3 -> outshop(ware);
case 4 -> showAllshop(ware);
default -> System.out.println("该选项不存在");
}
}
}

public static void show() {
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("**********************************************************");
}

public static void show1(String itemno1, String itemname1, String shipmenttime1, String suppliername1, String warehousenumber1, String warehouseplace1, int itemnumber1) {
System.out.println("***********************************************************");
System.out.println(" 石家庄铁道大学前进22软件开发有限公司 ");
System.out.println(" 仓库管理系统2022版 ");
System.out.println("***********************************************************");
System.out.println(" 商品编号:" + itemno1);
System.out.println(" 商品名称:" + itemname1);
System.out.println(" 供货商信息:" + shipmenttime1);
System.out.println(" 入库时间:" + suppliername1);
System.out.println(" 存放仓库号:" + warehousenumber1);
System.out.println(" 存放位置信息:" + warehouseplace1);
System.out.println(" 入库商品数量:" + itemnumber1);
}

public static void show2() {
System.out.println("***********************************************************");
System.out.println(" 石家庄铁道大学前进22软件开发有限公司 ");
System.out.println(" 仓库管理系统2022版 ");
System.out.println("***********************************************************");
System.out.println(" 请输入商品编号:XXXXXXXX ");
System.out.println("***********************************************************");
}

public static void show3(WarehouseInformation W) {
System.out.println("***********************************************************");
System.out.println(" 石家庄铁道大学前进22软件开发有限公司 ");
System.out.println(" 仓库管理系统2022版 ");
System.out.println("***********************************************************");
System.out.println(" 1、商品编号:" + W.itemno);
System.out.println(" 2、商品名称:" + W.itemname);
System.out.println(" 3、供货商信息:" + W.suppliername);
System.out.println(" 4、入库时间:" + W.shipmenttime);
System.out.println(" 5、存放仓库号:" + W.warehousenumber);
System.out.println(" 6、存放位置信息:" + W.warehouseplace);
System.out.println(" 7、入库商品数量:" + W.itemnumber);


}

public static int addshop(ArrayList<WarehouseInformation> ware) {
Scanner sc = new Scanner(System.in);
while (true) {
System.out.println("请输入相关信息");//11111111 小米 小米公司 20230101 20230102 111 00001122 10 5
System.out.println("1商品编号2商品名称3供货商名称4入库时间5出库时间6仓库编号7存放商品的具体位置8入库商品的数量9出库商品的数量");
String itemno1 = sc.next();
String itemname1 = sc.next();
String suppliername1 = sc.next();
String warehousingtime1 = sc.next();
String shipmenttime1 = sc.next();
String warehousenumber1 = sc.next();
String warehouseplace1 = sc.next();
int itemnumber1 = sc.nextInt();
int outnumber1 = sc.nextInt();
if (!itemno1.matches("\\d{8}") || !warehousingtime1.matches("\\d{8}") || !warehousenumber1.matches(".{3}") || !shipmenttime1.matches("\\d{8}")) {
System.out.println("信息错误,请重新输入");
continue;
}
if (shipmenttime1.compareTo(warehousingtime1) < 0 || warehouseplace1.matches("^\\d{4}YY\\d{2}$")) {
System.out.println("信息错误,请重新输入");
continue;
}
show1(itemno1, itemname1, shipmenttime1, suppliername1, warehousenumber1, warehouseplace1, itemnumber1);
System.out.println("**********************************************************");
show1(itemno1, itemname1, shipmenttime1, suppliername1, warehousenumber1, warehouseplace1, itemnumber1);
System.out.println("该商品入库操作已完成,是否提交(Y/N)");
System.out.println("**********************************************************");
String choice1 = sc.next();
if (choice1.equals("N")) {
continue;
}
if (choice1.equals("Y")) {
WarehouseInformation Shop = new WarehouseInformation(itemno1, itemname1, suppliername1, warehousingtime1, shipmenttime1, warehousenumber1, warehouseplace1, itemnumber1, outnumber1);
ware.add(Shop);
System.out.println("商品录入成功");
return 0;
}
}
}

public static int setshop(ArrayList<WarehouseInformation> ware) {
Scanner sc = new Scanner(System.in);
while (true) {
show2();
System.out.println("请输入八位商品编号:");
String itemno = sc.next();
for (WarehouseInformation W : ware) {
if (W.itemno.equals(itemno)) {
show3(W);
System.out.println(" 请选择需要修改的信息编号(1-7):");
System.out.println("***********************************************************");
int choice2 = sc.nextInt();
show3(W);
System.out.println(" 请选择需要修改的信息编号(1-7):" + choice2);
if (choice2 > 7 || choice2 < 1) {
System.out.println("该选项不存在");
break;
}
String choice3[] = {"商品编号", "商品名称", "供货商信息", "入库时间", "存放仓库号", "存放位置信息", "商品数量"};
System.out.print("请输入修改后的" + choice3[choice2 - 1] + ":");
String s = null;
int s1 = 0;
if (choice2 != 7) {
s = sc.next();
} else {
s1 = sc.nextInt();
}
System.out.println("***********************************************************");
System.out.println("请输入Y/N:");
String s2 = sc.next();
if (s2.equals("Y")) {
switch (choice2) {
case 1:
W.itemno = s;
System.out.println("商品修改成功");
break;
case 2:
W.itemname = s;
System.out.println("商品修改成功");
break;
case 3:
W.suppliername = s;
System.out.println("商品修改成功");
break;
case 4:
W.warehousingtime = s;
System.out.println("商品修改成功");
break;
case 5:
W.warehousenumber = s;
System.out.println("商品修改成功");
break;
case 6:
W.warehouseplace = s;
System.out.println("商品修改成功");
break;
case 7:
W.itemnumber = s1;
System.out.println("商品修改成功");
break;
default:
System.out.println("该选项不存在");
break;
}
}
return 0;
}
}
System.out.println("该商品不存在");
}
}

public static int outshop(ArrayList<WarehouseInformation> ware) {
Scanner sc = new Scanner(System.in);
while (true) {
show2();
System.out.println("请输入商品编号:");
String s = sc.next();
for (WarehouseInformation W : ware) {
if (s.equals(W.itemno)) {
show3(W);
System.out.println("出库时间:XXXXXXXXX");
System.out.println("出库数量:xxx");
System.out.println("**********************************************************");
System.out.println("请输入出库时间和出库数量");
String s1 = sc.next();
int s2 = sc.nextInt();
if (s1.compareTo(W.warehousingtime) < 0 || W.itemnumber - W.outnumber - s2 < 0) {
System.out.println("日期不正确或出库数量过大,请重新输入");
continue;
}
System.out.println("请输入是否保存Y/N");
String s3 = sc.next();
if (s3.equals("N")) {
continue;
}
if (s3.equals("Y")) {
W.shipmenttime = s1;
W.outnumber = s2 + W.outnumber;
System.out.println("商品出库成功");
return 0;
}
}
}
System.out.println("未保存或没有该商品,请重新输入");
}
}

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

int i = 0;
for (WarehouseInformation W : ware) {
i++;
int j = W.itemnumber - W.outnumber;
System.out.println(i + "、 " + "商品编号:" + W.itemno + "、商品名称:" + W.itemname + "、库存数量:" + j);
}
System.out.println("***********************************************************");
}

public static class WarehouseInformation {
String itemno;//商品编号
String itemname;//商品名称
String suppliername;//供货商名称
String warehousingtime;//入库时间
String shipmenttime;// 出库时间
String warehousenumber;//仓库编号
String warehouseplace;//存放商品的具体位置
int itemnumber;//入库商品的数量
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 WarehouseInformation() {
}

public WarehouseInformation(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;
}
}
}

标签:String,System,测试程序,sc,println,重写,public,out
From: https://www.cnblogs.com/zhaoqianwan/p/17703347.html

相关文章

  • 重载和重写的区别,equals与==的区别
    一、重载和重写的区别1.1重写(Override)从字面上看重写就是重新写一遍,其实就是子类继承父类并把父类中的方法重新写一遍。子类继承了父类原有的方法,但有时子类并不想原封不动的继承父类中的某个方法,所以在方法名,参数列表,返回类型(除过子类中方法的返回值是父类中方法返回值的子类时)......
  • 新人笔记-重写
    packagecom_black.jicheng;//手机类publicclassphone{publicvoidcall(Stringname){System.out.println("给"+name+"打电话");}}packagecom_black.jicheng;publicclassphone01extendsphone{@Override//注解可以帮助我们检查......
  • 手撕代码,函数重载和重写
    #include<bits/stdc++.h>usingnamespacestd;classanimal{public://纯虚函数//virtualvoidsound()=0;//虚函数virtualvoidsound(){cout<<"animalsound"<<endl;}voidsound(strings){......
  • iOS开发Swift-8-类的继承,方法重写,构造器,枚举类型,可选类型,强制解包,可选绑定,隐式
    1.类的继承classAnimal{funcbreathe(){//...}}classCat:Animal{varhasHair=true}letcat=Cat()cat.breathe()cat.hasHaiclassSmallCat:Cat{funceat(){//...}}letsmallCat=SmallCat()smallCat.breathe(......
  • 重写equals为什么还要重写hashcode
    重写equals为什么还要重写hashcode1、为了保证一个原则,equals相同的两个对象hashcode必须相同。如果重写了equals而没有重写hashcode,会出现equals相同hashcode不相同这个现象。2、在散列集合中,是使用hashcode来计算key应存储在hash表的索引,如果重写了equals而没有重写hashcode,......
  • C++虚函数 覆盖(重写)
    1、虚函数  在成员函数前面加virtual后,该函数就称为虚函数,此时该类就会像虚继承一样多了一个虚表指针(虚函数表指针、虚指针)2、虚函数表  虚表指针指向的是属于该类的一张表格的首地址,该表格中记录了该类中所有虚函数的首地址    如果类中没有其他成员变......
  • Prometheus监控实战系列八:标签重写
    标签重写(Relabeling)是Prometheus一个非常有用的功能,它可以在任务拉取(scraping)阶段前,修改target和它的labels。该功能在日常的监控中常常会使用到,值得我们好好了解。 一. 默认标签 默认情况下,Prometheus加载targets后,都会包含一些默认的标签,其中以__作为前置的标签是在系......
  • 为什么使用HashMap的键存的是自定义的键时需要重写hashcode和equals方法?
    当hashMap的键存的是自定义的键时需要重写对象的hashcode和equals方法存入的是对象时,应该hashMapd的键不能存储的值不能相同,如果重写方法的hashcode()方法,他会默认调用object类的hashcode方法,但是object的hashcode方法时地址值计算出来的hash值,并不是内容,这个时候就需要重......
  • 19-面向对象-方法重写(Override)
    基本介绍重写(Override):是指子类中有一个方法和父类的某个方法的名称、返回类型、参数完全一样,那么我们就说子类的这个方法覆盖了父类的方法即在Java中,子类在重写父类的方法时,必须与父类方法的修饰符、返回值类型、方法名(参数列表)要完全一致publicclassOverride01{pu......
  • Url重写隐藏网页路径技术
        Url重写:实质上是将网页真实的Url隐藏起来,使用户通过虚拟的Url来访问资源,以弥补真是Url的许多不足;作用:(1)满足搜索引擎的需要,实现搜索引擎排名的优化(2)隐藏网页实现技术,增强网站安全性(3)提高网站的安全性和实用性(4)Url支持"可删减"的需求下面通过代码来了解Url重写......