日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > java >内容正文

java

JavaEE实战班第十天

發布時間:2025/3/15 java 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 JavaEE实战班第十天 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

今天將昨天分成的任務達成了三個,還剩最后一個。其中遇到的問題封裝不會,生成隨機數不會。

代碼如下:

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) {
?? ??? ?startMenu();
?? ??? ?}
?? ?}
?? ?public static void startMenu() {
?? ??? ?// 展示菜單
?? ??? ??? ??? ?System.out.println("=======歡迎使用新職課快遞柜======");
?? ??? ??? ??? ?System.out.print("請輸入您的身份:1快遞員 2用戶");
?? ??? ??? ??? ?do {
?? ??? ??? ??? ?int id = input.nextInt();
?? ??? ??? ??? ?
?? ??? ??? ??? ?if(id==1) {//快遞員
?? ??? ??? ??? ??? ?deliverymanMenu();
?? ??? ??? ??? ??? ?break;
?? ??? ??? ??? ?}else if(id==2) {//用戶
?? ??? ??? ??? ??? ?userMenu();
?? ??? ??? ??? ??? ?break;
?? ??? ??? ??? ?}else {
?? ??? ??? ??? ??? ?System.out.println("選擇有誤,請重新輸入");
?? ??? ??? ??? ?}
?? ??? ??? ??? ?}while(true);
?? ?}
?? ?//--------------------------------------------------------------------------
?? ?public static void userMenu() {
?? ??? ?System.out.print("請輸入取件碼:");
?? ??? ?int code = input.nextInt();
?? ?}
?? ?//--------------------------------------------------------------------------
?? ?
?? ?//--------------------------------------------------------------------------
?? ?public static void deliverymanMenu() {
?? ??? ?System.out.print("請選擇操作:1存快遞 2刪除快遞 3修改快遞信息 4查看所有快遞");
?? ??? ?int id = input.nextInt();
?? ??? ?if(id==1){
?? ??? ??? ?saveExpress();
?? ??? ?}else if(id==2) {
?? ??? ??? ?System.out.println("請輸入要刪除的快遞單號");
?? ??? ??? ?String number=input.next();
?? ??? ??? ?int delIndex=findByNumber(number);
?? ??? ??? ?if(delIndex==-1) {
?? ??? ??? ??? ?System.out.println("未找到快遞");
?? ??? ??? ?}else {
?? ??? ??? ??? ?//刪除
?? ??? ??? ??? ?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--;
?? ??? ??? ??? ?System.out.println("刪除成功");
?? ??? ??? ??? ?
?? ??? ??? ?}
?? ??? ?}else if(id==3) {
?? ??? ??? ?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));
?? ??? ?codeArr[index]=code;
?? ??? ?index++;
?? ??? ?System.out.println("取件碼是:"+code);
?? ?}
//--------------------------------------------------------------------------
public static void delExpress() {
?? ??? ?
?? ?}
//--------------------------------------------------------------------------
?? ?public static boolean isExist(int code) {
?? ??? ?for(int i = 0;i<index;i++) {
?? ??? ??? ?if(codeArr[i]==code) {
?? ??? ??? ??? ?return true;
?? ??? ??? ?}
?? ??? ?}
?? ??? ?return false;
?? ?
?? ?}
}

總結

以上是生活随笔為你收集整理的JavaEE实战班第十天的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。