初學java小專案-快遞E棧
阿新 • • 發佈:2021-01-17
快遞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;
}
}
}
}
還有很多需要補充的內容,例如存快遞,快遞號的檢驗,不能重複等。。。大家有興趣自己修改或者留言探討