快递E栈
下面展示一些 内联代码片
。
import java.util.Random;
import java.util.Scanner;
public class ExpressService {
/**
* 快递E栈服务
*/
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
//接收数据类型
Random random = new Random();
//随机数
boolean a = true;
boolean b = true;
int index = 0;
//次数索引
int[] number = new int[20];
String[] company = new String[20];
int[] code = new int[20];
//快递数据
while (b) {
System.out.println("======欢迎使用新职课快递柜======");
System.out.println("请输入您的身份:1-快递员1,2-用户,3-退出,其他返回");
int user = scanner.nextInt();
//用户类别
if (user == 1) {
System.out.println("请选择操作:1-存快递,2-删除快递,3-修改快递信息,4-查看快递");
int select = scanner.nextInt();
//快递员操作选项
switch (select) {
case 1:
while (a) {
System.out.println("请输入快递号");
int inputNumber = scanner.nextInt();
System.out.println("请输入公司名");
String inputCompany = scanner.next();
int inputCode = random.nextInt(999);
//999以内随机数
number[index] = inputNumber;
company[index] = inputCompany;
code[index] = inputCode;
System.out.println("快递已存入,取件码是:"+code[index]);
index++;
System.out.println("是否继续 y/n");
String goOn = scanner.next();
if (goOn.equals("y")) {
a = true;
} else {
a = false;
}
}
break;
//存快递
case 2:
boolean isDelete = false;
System.out.println("请输入要删除的快递单号: ");
int deleteNumber = scanner.nextInt();
for (int i = 0; i < number.length; i++) {
if (number[i] == deleteNumber) {
number[i] = 0;
company[i] = "";
code[i] = 0;
isDelete = true;
break;
}
}
if (isDelete) {
System.out.println("删除成功");
} else {
System.out.println("未找到快递");
}
break;
//删除快递
case 3:
boolean isUpdate = false;
System.out.println("请输入要修改的快递单号: ");
int update = scanner.nextInt();
for (int i = 0; i < number.length; i++) {
if (number[i] == update) {
System.out.println("请输入要修改的快递单号: ");
int updateNumbr = scanner.nextInt();
System.out.println("请输入要修改的快递单号: ");
String updateCompany = scanner.next();
number[i] = updateNumbr;
company[i] = updateCompany;
isUpdate = true;
break;
}
}
if (isUpdate) {
System.out.println("修改成功");
} else {
System.out.println("未找到快递");
}
break;
//修改快递信息
case 4:
System.out.println("所有快递信息如下:");
System.out.println("快递单号\t公司名称\t取件码");
for (int i = 0; i < number.length; i++) {
if (number[i] != 0) {
System.out.println(number[i] + "\t " + company[i] + "\t " + code[i]);
}
}
break;
//查询快递信息
default:
System.out.println("输入错误请重新输入");
break;
}
} else if (user == 2) {
System.out.println("请输入取件码:");
int goodsCode = scanner.nextInt();
//取件码
boolean isGet = false;
for (int i=0;i<code.length;i++) {
if (code[i] == goodsCode) {
number[i] = 0;
company[i] = "";
code[i] = 0;
isGet = true;
break;
}
}
if (isGet) {
System.out.println("取件成功");
} else {
System.out.println("未找到快递");
}
//用户取件
}else if (user == 3) {
System.out.println("服务结束,再见!");
break;
//退出
}else {
continue;
}
}
}
}
还有很多需要补充的内容,例如存快递,快递号的检验,不能重复等。。。大家有兴趣自己修改或者留言探讨
已更新进阶版快递E栈——MVC结构二维数组存储数据
链接: 快递E站——MVC结构二维数组存储数据.