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

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > windows >内容正文

windows

快递e站系统

發(fā)布時間:2024/3/26 windows 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 快递e站系统 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
package com.kkb.pojo;//beanpublic class Express {private String number;private String company;private Integer code; //構(gòu)造方法public Express(){}@Overridepublic String toString() {return number+"-"+company+"-"+code;}public Express(String number, String company, Integer code) {this.number = number;this.company = company;this.code = code;}public String getNumber() {return number;}public void setNumber(String number) {this.number = number;}public String getCompany() {return company;}public void setCompany(String company) {this.company = company;}public Integer getCode() {return code;}public void setCode(Integer code) {this.code = code;} }

-------------------------------------------------------------------------------------------------------------

package com.kkb.dao;import com.kkb.pojo.Coordinate; import com.kkb.pojo.Express;import java.rmi.server.ExportException; import java.util.Random;/* 快遞管理*/ public class ExpressDao {private Express[][] expressArr=new Express[10][10];//表示快遞的柜子private int size=0;//表示快遞柜中有多少個快遞public ExpressDao() {//添加幾個快遞expressArr[0][0]=new Express("10001","順豐",123456);expressArr[2][1]=new Express("10002","圓通",112233);expressArr[5][2]=new Express("12321","中通",159463);size=3;}/*** 根據(jù)坐標(biāo)去獲取快遞* @param x* @param y* @return*/public Express findExpressByCoordinate(int x,int y){return expressArr[x][y];}/*** 根據(jù)取件碼查詢快遞的位置* @param code* @return*/public Coordinate findExpressByCode(int code) {for (int i = 0; i < 10; i++) {for (int j = 0; j < 10; j++) {if (expressArr[i][j] != null && expressArr[i][j].getCode() == code)return new Coordinate(i, j);}}return null;}/*** 根據(jù)快遞單號去修改快遞* @param number* @return*/public boolean update(String number,Express newExpress) throws Exception {//判斷該單號的快遞是否存在Coordinate coordinate=findExpressByNumber(number);if (coordinate==null){throw new Exception("該快遞不存在");}//根據(jù)坐標(biāo)獲取到要修改的快遞Express expresses=expressArr[coordinate.getX()][coordinate.getY()];//修改該快遞的公司和單號expresses.setCompany(newExpress.getCompany());expresses.setNumber(newExpress.getNumber());return true;}/*** 根據(jù)快遞單號來進(jìn)行刪除* @param number* @return*/public boolean delete(String number) throws Exception {//判斷該單號的快遞是否存在Coordinate coordinate=findExpressByNumber(number);if (coordinate==null){throw new Exception("該快遞不存在");}expressArr[coordinate.getX()][coordinate.getY()]=null;//表示刪除size--;//實際的快遞個數(shù)return true;}/*** 根據(jù)我們的快遞單號查找* @param number* @return*/public Coordinate findExpressByNumber(String number){for (int i=0;i<10;i++){for (int j=0;j<10;j++){if (expressArr[i][j]!=null &&expressArr[i][j].getNumber().equals(number))return new Coordinate(i,j);}}return null;}/*** 添加一個快遞到快遞柜中* @param express* @return*/public Coordinate add(Express express) throws Exception {if (size==100){//如果滿了throw new Exception("快遞柜已滿,不能添加快遞了");}Random random=new Random();int x,y;do {x = random.nextInt(10);y = random.nextInt(10);}while(expressArr[x][y]!=null);//該位置有快遞,重新生成坐標(biāo)//系統(tǒng)產(chǎn)生隨機(jī)的取件碼int code;do {code = random.nextInt(900000) + 100000;}while (isExistCode(code));//如果重復(fù)就要重新生成express.setCode(code);//設(shè)置取件碼expressArr[x][y]=express;size++;//添加一個快遞我們的實際數(shù)量要加一return new Coordinate(x,y);}/*** 判斷取件碼是否重復(fù)* @param code* @return*/public boolean isExistCode(int code){for (int i=0;i<10;i++){for (int j=0;j<10;j++){if (expressArr[i][j]!=null && expressArr[i][j].getCode()==code)return true;}}return false;}/*獲取快遞柜*/public Express[][] getAllExpress(){return expressArr;}public int getSize() {return size;} }

-----------------------------------------------------------------------------------------------------------

package com.kkb.pojo;public class Coordinate {private int x;private int y;public Coordinate(){}public Coordinate(int x,int y){this.x = x;this.y = y;}public int getX(){return x;}public void setX(int x){this.x = x;}public int getY(){return y;}public void setY(int y){this.y = y;} }

-------------------------------------------------------------------------------------------------

package com.kkb.view;import com.kkb.dao.ExpressDao; import com.kkb.exception.OutNumberBoundException; import com.kkb.pojo.Coordinate; import com.kkb.pojo.Express;import java.util.Scanner;public class View {private Scanner input=new Scanner(System.in);private ExpressDao expressDao=new ExpressDao();/*** 起始菜單* @return*/public int startMenu() {int num=0;do{System.out.println("----歡迎來到開課吧快遞管理系統(tǒng)-----");System.out.println("請選擇:");System.out.println("1.管理員");System.out.println("2.普通用戶");System.out.println("0.退出");String strNum = input.nextLine();try {num = validateNum(strNum,0,2);break;} catch (NumberFormatException e) {System.err.println(e.getMessage());//e.printStackTrace();} catch (OutNumberBoundException e) {System.err.println(e.getMessage());//e.printStackTrace();}}while(true);if (num==1){administorMenu();}else if (num==2){userMenu();}else if (num==0) {System.out.println("謝謝使用");}return num;}/*** 用戶的菜單*/public void userMenu(){int code;do {System.out.print("請輸入取件碼");String strCode = input.nextLine();try {code = validateNum(strCode, 100000, 900000);break;} catch (OutNumberBoundException e) {e.printStackTrace();}}while (true);//調(diào)用dao中的方法判斷取件碼是否存在Coordinate coordinate=expressDao.findExpressByCode(code);if(coordinate!=null){int x=coordinate.getX();int y=coordinate.getY();//根據(jù)坐標(biāo)獲取快遞信息Express express=expressDao.findExpressByCoordinate(x,y);System.out.println("快遞信息:");System.out.println("\t所在位置:柜子的第"+(x+1)+"排第"+(y+1)+"列");System.out.println("\t"+express);//從柜子當(dāng)中去移除try {if (expressDao.delete(express.getNumber()))System.out.println("刪除成功");} catch (Exception exception) {//exception.printStackTrace();System.err.println("刪除失敗"+exception.getMessage());}}else{System.out.println("該取件碼不存在");}}/*管理員的菜單*/private void administorMenu() {int num;do {System.out.println("1.快遞錄入");System.out.println("2.快遞刪除");System.out.println("3.快遞修改");System.out.println("4.查看所有快遞");System.out.println("0.返回上一級菜單");System.out.print("請選擇功能序號");String strNum = input.nextLine();try {num = validateNum(strNum, 0, 4);break;} catch (NumberFormatException e) {System.err.println(e.getMessage());//e.printStackTrace();} catch (OutNumberBoundException e) {System.err.println(e.getMessage());//e.printStackTrace();}}while (true);if (num==1){addExpress();}else if (num==2){deleteExpress();}else if (num==3){updateExpress();}else if (num==4){System.out.println("------查看所有快遞------");Express[][] allExpress = expressDao.getAllExpress();printByGrid(allExpress);//printAllExpress(allExpress);}else if (num==0){startMenu();}}/*** 修改快遞*/private void updateExpress(){System.out.println("----------快遞修改--------");System.out.println("請輸入要修改的快遞單號");String number=input.nextLine();Express newExpress=new Express();System.out.println("請輸入修改后的快遞單號和公司");newExpress.setNumber(input.nextLine());newExpress.setCompany(input.nextLine());try {if (expressDao.update(number,newExpress)){System.out.println("修改成功");}else{System.out.println("修改失敗");}} catch (Exception exception) {System.out.println("修改失敗");System.out.println(exception.getMessage());//exception.printStackTrace();}}/*** 刪除快遞*/private void deleteExpress(){System.out.println("-----快遞刪除-----");System.out.println("請輸入要刪除的快遞單號");String number=input.nextLine();try {if(expressDao.delete(number)){System.out.println("刪除成功");}else {System.out.println("刪除失敗");}} catch (Exception exception) {System.out.println("刪除失敗");System.err.println(exception.getMessage());//exception.printStackTrace();}}/*** 快遞錄入*/private void addExpress() {System.out.println("-----快遞錄入------");Express express = new Express();System.out.println("請輸入快遞單號和公司");express.setNumber(input.nextLine());express.setCompany(input.nextLine());try {Coordinate coordinate = expressDao.add(express);System.out.println("添加成功,放在了快遞柜當(dāng)中的第" + (coordinate.getX() + 1) + "排第" + (coordinate.getY() + 1) + "列");System.out.println("快遞柜中共有" + expressDao.getSize() + "個快遞");} catch (Exception exception) {System.out.println("添加失敗");System.err.println(exception.getMessage());exception.printStackTrace();}}/*** 打印快遞柜當(dāng)中的所有非空的格子中的快遞信息* @param allExpress*/private void printAllExpress(Express[][] allExpress) {for (int i = 0; i < allExpress.length; i++) {for (int j = 0; j < allExpress[i].length; j++) {if (allExpress[i][j] != null)System.out.println(allExpress[i][j]);}}}/*** 按照快遞柜的方式打印快遞信息* @param allExpress*/private void printByGrid(Express[][] allExpress) {for (int i = 0; i < allExpress.length; i++) {for (int j = 0; j < allExpress[i].length; j++) {if(allExpress[i][j]==null){System.out.printf("%-20s","空\t");}elseSystem.out.printf("%-20s",allExpress[i][j]+"\t");}System.out.println();}}private int validateNum(String strNum,int begin,int end) throws NumberFormatException,OutNumberBoundException{try{int num=Integer.valueOf(strNum);if (num<begin || num>end){throw new OutNumberBoundException("數(shù)字范圍必須在"+begin+"和"+end+"之間!");}return num;}catch (NumberFormatException exception){throw new NumberFormatException("輸入的必須是數(shù)字");}} }

----------------------------------------------------------------------

調(diào)試

package com.kkb.test;import com.kkb.view.View;public class MainTest {public static void main(String[] args) {View view=new View();while(true) {if(view.startMenu()==0)break;}} }

-------------------------------------------------------------------------------

package com.kkb.exception;public class OutNumberBoundException extends Throwable {public OutNumberBoundException(String s) {super(s);} }

總結(jié)

以上是生活随笔為你收集整理的快递e站系统的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。