package com.chainup.controller;
import com.chainup.bean.ExpressBean;
import java.util.Random;
import java.util.Scanner;
/**
* @Author
* @Date 2021/9/7 21:37
*/
public class Express {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("欢迎使用快递驿站");
ExpressBean[] nums = new ExpressBean[100];
while (true) {
System.out.println("请选择身份:1.管理员 2.用户");
String s = sc.nextLine();
if ("1".equals(s)) {
System.out.println("请选择操作:1-存快递 2-删除快递 3-修改快递信息 4-查看所有快递信息");
String input = sc.nextLine();
if ("1".equals(input)) {
ExpressBean expressBean = new ExpressBean();
System.out.println("请输入快递单号");
String number = sc.nextLine();
expressBean.setNumber(number);
System.out.println("请输入公司名称");
String company = sc.nextLine();
expressBean.setCompanyName(company);
Random random = new Random();
String numberCode = random.nextInt(899) + 100 + "";
expressBean.setCode(numberCode);
//遍历数组找到空的柜子
for (int i = 0; i < nums.length; i++) {
if (nums[i] == null) {
nums[i] = expressBean;
System.out.println("快递已经存入,取件码是:" + expressBean.getCode());
break;
}
if (i == nums.length - 1) {
System.out.println("快递柜全满");
}
}
}else if ("2".equals(input)) {
System.out.println("请输入要删除的快递单号:");
String number = sc.nextLine();
for (int i = 0; i < nums.length; i++) {
if (nums[i] != null && nums[i].getNumber().equals(number)) {
nums[i] = null;
System.out.println("删除成功!");
break;
}
if (i >= nums.length - 1) {
System.out.println("未找到快递!");
}
}
}else if ("3".equals(input)) {
System.out.println("请输入要修改的快递单号:");
String number = sc.nextLine();
for (int i = 0; i < nums.length; i++) {
if (nums[i] != null && nums[i].getNumber().equals(number)) {
System.out.println("找到->单号:" + nums[i].getNumber() + ",公司名称:" + nums[i].getCompanyName() + ",取件码:" + nums[i].getCode());
System.out.println("请输入新快递单号");
String newNumber = sc.nextLine();
nums[i].setNumber(newNumber);
System.out.println("请输入新公司名称");
String company = sc.nextLine();
nums[i].setCompanyName(company);
System.out.println("修改->单号:" + nums[i].getNumber() + ",公司名称:" + nums[i].getCompanyName() + ",取件码:" + nums[i].getCode());
break;
}
if (i >= nums.length - 1) {
System.out.println("未找到快递!");
}
}
}else if ("4".equals(input)) {
System.out.println("所以快递信息如下");
for (int i = 0; i < nums.length; i++) {
if (nums[i] != null) {
System.out.println("单号:" + nums[i].getNumber() + ",公司名称:" + nums[i].getCompanyName() + ",取件码:" + nums[i].getCode());
}
}
}else {
System.out.println("输入错误,请重新输入");
continue;
}
}else if ("2".equals(s)) {
System.out.println("请输入取件码:");
String code = sc.nextLine();
for (int i = 0; i < nums.length; i++) {
if (nums[i] != null && nums[i].getCode().equals(code)) {
System.out.println("取件成功!");
nums[i] = null;
break;
}
if (i == nums.length - 1) {
System.out.println("取件码错误!");
}
}
}else {
System.out.println("输入错误,请重新输入");
continue;
}
}
}
}
public class ExpressBean {
/**
* 快递单号
*/
private String number;
/**
* 公司名称
*/
private String companyName;
/**
* 取件码
*/
private String code;
public String getNumber() {
return number;
}
public void setNumber(String number) {
this.number = number;
}
public String getCompanyName() {
return companyName;
}
public void setCompanyName(String companyName) {
this.companyName = companyName;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
}
|