上午学习英语,背了会儿单词,准备四级考试。下午简单学习了会儿Java,完成了Java开学测试的重写
package xinde;
public class WarehouseInformation {
private String code;
private String name;
private String supplier;
private String time;
private String warehouseNumber;
private String location;
private int quantity;
public WarehouseInformation(String code, String name, String supplier, String time, String warehouseNumber, String location, int quantity) {
this.code = code;
this.name = name;
this.supplier = supplier;
this.time = time;
this.warehouseNumber = warehouseNumber;
this.location = location;
this.quantity = quantity;
}
}
package xinde;
import java.util.Scanner;
public class WarehouseManagement {
private static WarehouseInformation[] warehouse = new WarehouseInformation[100]; // 假设最多存储100条仓库信息
private static int warehouseCount = 0; // 当前仓库信息数量
public static void main(String[] args) {
mainFrame();
}
public static void mainFrame() {
System.out.println("欢迎使用仓库管理系统!");
System.out.println("1. 商品入库");
System.out.println("2. 商品修改");
System.out.println("3. 商品出库");
System.out.println("4. 统计商品库存数量");
System.out.println("0. 退出系统");
Scanner scanner = new Scanner(System.in);
int choice = scanner.nextInt();
switch (choice) {
case 1:
goodsWarehousing();
break;
case 2:
modifyWarehouse();
break;
case 3:
outboundWarehouse();
break;
case 4:
countGoods();
break;
case 0:
System.out.println("感谢使用仓库管理系统,再见!");
System.exit(0);
break;
default:
System.out.println("输入有误,请重新输入!");
mainFrame();
break;
}
}
public static void goodsWarehousing() {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入商品编号:");
String code = scanner.nextLine();
// 判断商品编号是否正确
// ...
System.out.println("请输入商品名称:");
String name = scanner.nextLine();
System.out.println("请输入供货商信息:");
String supplier = scanner.nextLine();
System.out.println("请输入入库时间:");
String time = scanner.nextLine();
System.out.println("请输入存放仓库号:");
String warehouseNumber = scanner.nextLine();
System.out.println("请输入存放位置信息:");
String location = scanner.nextLine();
System.out.println("请输入入库数量:");
int quantity = scanner.nextInt();
if (quantity <= 0) {
System.out.println("入库数量需大于0,请重新输入!");
goodsWarehousing();
} else {
System.out.println("是否确认入库(Y/N)?");
String confirm = scanner.next();
if (confirm.equalsIgnoreCase("Y")) {
addData(code, name, supplier, time, warehouseNumber, location, quantity);
System.out.println("商品入库成功!");
} else {
System.out.println("商品入库取消!");
}
mainFrame();
}
}
public static void modifyWarehouse() {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入商品编号:");
String code = scanner.nextLine();
// 判断商品是否存在
// ...
// 显示商品信息
// ...
System.out.println("请选择需要修改的信息编号(1-7):");
int choice = scanner.nextInt();
switch (choice) {
case 1:
System.out.println("请输入新的商品编码:");
String newCode = scanner.next();
modifyData(code, choice, newCode);
break;
case 2:
System.out.println("请输入新的商品名称:");
String newName = scanner.next();
modifyData(code, choice, newName);
break;
// ...
case 7:
System.out.println("请输入新的入库数量:");
int newQuantity = scanner.nextInt();
modifyData(code, choice, newQuantity);
break;
default:
System.out.println("输入有误,请重新输入!");
modifyWarehouse();
break;
}
System.out.println("商品修改成功!");
mainFrame();
}
public static void outboundWarehouse() {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入商品编号:");
String code = scanner.nextLine();
// 判断商品是否存在
// ...
// 显示商品信息
// ...
// 计算库存数量
// ...
System.out.println("请输入出库数量:");
int quantity = scanner.nextInt();
// 判断出库数量是否小于库存数量
// ...
System.out.println("是否确认出库(Y/N)?");
String confirm = scanner.next();
if (confirm.equalsIgnoreCase("Y")) {
modifyData(code, 7, quantity);
System.out.println("商品出库成功!");
} else {
System.out.println("商品出库取消!");
}
mainFrame();
}
public static void countGoods() {
// 按照商品编号分组统计库存数量
// ...
// 显示统计结果
// ...
mainFrame();
}
public static void addData(String code, String name, String supplier, String time, String warehouseNumber, String location, int quantity) {
warehouse[warehouseCount] = new WarehouseInformation(code, name, supplier, time, warehouseNumber, location, quantity);
warehouseCount++;
}
public static void modifyData(String code, int choice, Object newValue) {
// 根据商品编号查找对应的仓库信息
// ...
// 修改对应的信息
// ...
}
}
标签:code,scanner,String,9.13,System,println,out From: https://www.cnblogs.com/jais/p/17700952.html