JavaEE实战班第十一天
今天完成了任務(wù)的最后一個模塊,整個任務(wù)全部完成并可以使用。發(fā)現(xiàn)其中有很多沒學(xué)過的東西。
第一次完成這么龐大的任務(wù),上上下下封裝有的時候甚至找不到想改的模塊。而后學(xué)習(xí)了第七節(jié),對未來就業(yè)觀念有了一定的改觀。
package day09;
import java.util.Random;
import java.util.Scanner;
public class work01 {
?? ?public static Scanner input = new Scanner(System.in);
?? ?public static String[] numberArr=new String[100];
?? ?public static String[] companyArr=new String[100];
?? ?public static int[] codeArr=new int[100];
?? ?public static int index = 0;//有多少個快遞
?? ?public static Random random = new Random();
?? ?public static void main(String[] args) {
?? ??? ?while(true) {
?? ??? ?int id = startMenu();
?? ??? ?if(id==0) {
?? ??? ??? ?return;
?? ??? ?}
?? ??? ?}
?? ?}
?? ?public static int startMenu() {
?? ??? ?// 展示菜單
?? ??? ??? ??? ?System.out.println("=======歡迎使用新職課快遞柜======");
?? ??? ??? ??? ?System.out.print("請輸入您的身份:1快遞員 2用戶 0退出");
?? ??? ??? ??? ?int id = 0;
?? ??? ??? ??? ?do {
?? ??? ??? ??? ? id = input.nextInt();
?? ??? ??? ??? ?
?? ??? ??? ??? ?if(id==1) {//快遞員
?? ??? ??? ??? ??? ?deliverymanMenu();
?? ??? ??? ??? ??? ?break;
?? ??? ??? ??? ?}else if(id==2) {//用戶
?? ??? ??? ??? ??? ?userMenu();
?? ??? ??? ??? ??? ?break;
?? ??? ??? ??? ?}else if(id==0){
?? ??? ??? ??? ??? ?System.out.println("謝謝使用");
?? ??? ??? ??? ??? ?return 0;
?? ??? ??? ??? ?}else {
?? ??? ??? ??? ??? ?System.out.println("選擇有誤,請重新輸入");
?? ??? ??? ??? ?}
?? ??? ??? ??? ?}while(true);
?? ??? ??? ??? ?return id;
?? ?}
?? ?//--------------------------------------------------------------------------
?? ?public static void userMenu() {
?? ??? ?System.out.print("請輸入取件碼:");
?? ??? ?int code = input.nextInt();
?? ??? ?int codeIndex = isExist(code);
?? ??? ?if(codeIndex==-1) {
?? ??? ??? ?System.out.print("未找到快遞:");
?? ??? ?}else {
?? ??? ??? ?del(codeIndex);
?? ??? ??? ?System.out.print("取件成功:");
?? ??? ?}
?? ?}
?? ?//--------------------------------------------------------------------------
?? ?
?? ?//--------------------------------------------------------------------------
?? ?public static void deliverymanMenu() {
?? ??? ?System.out.print("請選擇操作:1存快遞 2刪除快遞 3修改快遞信息 4查看所有快遞");
?? ??? ?int id = input.nextInt();
?? ??? ?if(id==1){
?? ??? ??? ?saveExpress();
?? ??? ?}else if(id==2) {
?? ??? ??? ?
?? ??? ??? ?delExpress();
?? ??? ??? ?
?? ??? ?}else if(id==3) {
?? ??? ??? ?System.out.println("請輸入要修改的快遞信息");
?? ??? ??? ?String number = input.next();
?? ??? ??? ?int updateIndex=findByNumber(number);
?? ??? ??? ?if(updateIndex==-1) {
?? ??? ??? ??? ?System.out.println("未找到快遞");
?? ??? ??? ?}else {
?? ??? ??? ??? ?System.out.println("請輸入新的快遞信息");
?? ??? ??? ??? ? number = input.next();
?? ??? ??? ??? ?System.out.println("請輸入新的公司名稱");
?? ??? ??? ??? ?String company = input.next();
?? ??? ??? ??? ?numberArr[updateIndex]=number;
?? ??? ??? ??? ?companyArr[updateIndex]=company;
?? ??? ??? ??? ?System.out.println("修改成功");
?? ??? ??? ?}
?? ??? ?}else if(id==4) {
?? ??? ??? ?printAll();
?? ??? ?}
?? ?}
?? ?//--------------------------------------------------------------------------
?? ?public static void printAll() {
?? ??? ?System.out.println("----------這是所有的快遞信息-----------");
?? ??? ?System.out.println("快遞單號\t快遞公司\t取件碼");
?? ??? ?for(int i = 0;i<index;i++) {
?? ??? ??? ?System.out.println(numberArr[i]+"\t"+companyArr[i]+"\t"+codeArr[i]);
?? ??? ?}
?? ?}
?? ?//--------------------------------------------------------------------------
?? ?public static int findByNumber(String number) {
?? ??? ?for(int i = 0;i<index;i++) {
?? ??? ??? ?if(numberArr[i].equals(number)) {
?? ??? ??? ??? ?return i;
?? ??? ??? ?}
?? ??? ?}
?? ??? ?return -1;
?? ?}
?? ?//--------------------------------------------------------------------------
?? ?public static void ?saveExpress() {
?? ??? ?System.out.println("請輸入快遞單號");
?? ??? ?String number=input.next();
?? ??? ?System.out.println("請輸入公司名稱");
?? ??? ?String company=input.next();
?? ??? ?int code =0;?
?? ??? ?numberArr[index]=number;
?? ??? ?companyArr[index]=company;
?? ??? ?do {
?? ??? ??? ?code =random.nextInt(900)+100;
?? ??? ?}while(isExist(code)!=-1);
?? ??? ?codeArr[index]=code;
?? ??? ?index++;
?? ??? ?System.out.println("取件碼是:"+code);
?? ?}
//--------------------------------------------------------------------------
public static void delExpress() {
?? ?System.out.println("請輸入要刪除的快遞單號");
?? ?String number=input.next();
?? ?int delIndex=findByNumber(number);
?? ?if(delIndex==-1) {
?? ??? ?System.out.println("未找到快遞");
?? ?}else {
?? ??? ?//刪除
?? ??? ?del(delIndex);
?? ??? ?System.out.println("刪除成功");}
?? ?}
//--------------------------------------------------------------------------
?? ?public static void del(int delIndex) {
?? ??? ?if(delIndex!=numberArr.length-1) {
?? ??? ??? ?
?? ??? ??? ?for(int i = delIndex;i<index;i++) {
?? ??? ??? ??? ?numberArr[i]=numberArr[i+1];
?? ??? ??? ??? ?companyArr[i]=companyArr[i+1];
?? ??? ??? ??? ?codeArr[i]=codeArr[i+1];
?? ??? ??? ?}
?? ??? ??? ?
?? ??? ?}
?? ??? ?index--;
?? ?}
//--------------------------------------------------------------------------
?? ?public static int isExist(int code) {
?? ??? ?for(int i = 0;i<index;i++) {
?? ??? ??? ?if(codeArr[i]==code) {
?? ??? ??? ??? ?return i;
?? ??? ??? ?}
?? ??? ?}
?? ??? ?return -1;
?? ?
?? ?}
}
總結(jié)
以上是生活随笔為你收集整理的JavaEE实战班第十一天的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: URL生成方式性能优化结果
- 下一篇: [技术回顾系列]--认识WebServi