JAVA基礎代碼分享--DVD管理,java基礎代碼--dvd

來源:互聯網
上載者:User

JAVA基礎代碼分享--DVD管理,java基礎代碼--dvd

問題描述

為某音像店開發一個迷你DVD管理器,最多可存6張DVD,實現碟片的管理。

管理器具備的功能主要有:

  1、查看DVD資訊。

  菜單選擇查看功能,展示DVD的資訊。

 

  2、新增DVD資訊

 

  選擇新增功能,根據提示輸入新增的DVD名稱,添加到庫存,如果DVD貨架已滿,即達到6張,則提示增加失敗。

 

  3、刪除DVD資訊

 

  執行刪除命令,輸入要刪除的DVD的名稱,如果DVD為借出狀態,不允許刪除。如果沒有該DVD資訊,則提示“沒有找到匹配資訊”;

 

  4、借出DVD

 

  如果該DVD已經被借出,則系統提示“XX已經被借出”。如果沒有找到該DVD資訊,則系統提示“沒有找到匹配資訊!”。而且一個月預設為31天,如果輸入的借出日期為大於31的數字,則系統給出提示“必須輸入大於等於 1且小於等於31的數字,請重新輸入”。

 

  5、歸還DVD

 

  計算租金,1天1元。如果歸還的DVD未被借出,則系統提示“該DVD沒有被借出,無法進行歸還操作。如果歸還的DVD與列表中的DVD不匹配,則系統提示“沒有找到匹配資訊”。,如果歸還時間小於借出時間,或者是大於31的數字,則系統分別提示“歸還日期不能小於借出日期,請重新輸入,和一個月只有31天,請重新輸入。”

 

  6、當使用者執行退出命令時,結束本程式。

代碼分享

 

 

public class ManagerDVD {    private static String [][] dvdstr = new String[6][5];    private static int n = 0;//使用者輸入的操作命令    private static Scanner in;//數字輸入    private static Scanner input;//漢字輸入    private static String name = null;//DVD名字        public static void main(String[] args) {        System.out.println("--------------------歡迎使用DVD管理系統--------------------");        System.out.println("系統的操作命令:\n1、添加DVD\n2、刪除DVD\n3、查看DVD\n4、借出DVD\n5、歸還DVD\n0、登出退出");        in = new Scanner(System.in);        for(int i=0; i<6; i++){            dvdstr[i][0] = ""+(i+1);            dvdstr[i][4] = "0";        }        do {            System.out.print("請輸入操作命令:");            n = in.nextInt();            if(n!=0){                setManager(n);            }        } while (n!=0);    }    private static void setManager(int n) {        switch (n) {        case 1:            System.out.println("添加DVD");            if(dvdstr[5][2]!=null){                System.out.println("DVD庫存已滿,無法添加");                break;            }            System.out.print("請輸入DVD名字:");            input = new Scanner(System.in);            name = input.nextLine();            boolean boo = true;            for(int i=0; i<6; i++){                if(dvdstr[i][2]!=null&&name.equals(dvdstr[i][2])){                    boo = false;                    break;                }            }            if(boo){                for(int i=0; i<6; i++){                    if(dvdstr[i][2]==null){                        dvdstr[i][1] = "未借出";                        dvdstr[i][2] = name;                        System.out.println("添加操作完成");                        break;                    }                }            }else{                System.out.println("該DVD已存在");            }            break;        case 2:            System.out.println("刪除DVD");            if(dvdstr[0][2]==null){                System.out.println("庫存還沒有DVD,無法進行刪除操作");                break;            }            System.out.print("請輸入DVD名字:");            input = new Scanner(System.in);            name = input.nextLine();            boolean bo = false;            for(int i=0; i<6; i++){                if(dvdstr[i][2]!=null&&name.equals(dvdstr[i][2])){                    for(int j=i; j<5; j++){                        dvdstr[j][1] = dvdstr[j+1][1];                        dvdstr[j][2] = dvdstr[j+1][2];                        dvdstr[j][3] = dvdstr[j+1][3];                        dvdstr[j][4] = dvdstr[j+1][4];                    }                    dvdstr[5][1] = null;                    dvdstr[5][2] = null;                    dvdstr[5][3] = null;                    dvdstr[5][4] = null;                    bo = true;                    break;                }            }            if(bo){                System.out.println("刪除操作成功");            }else{                System.out.println("未找到該商品");            }            break;        case 3:            System.out.println("查看DVD");            System.out.println("序號\t狀態\t名稱\t\t借出日期\t借出次數");            for(int i=0; i<6; i++){                if(dvdstr[i][2]==null){                    break;                }                System.out.println(dvdstr[i][0]+"\t"+dvdstr[i][1]+"\t"+dvdstr[i][2]+"\t\t"+dvdstr[i][3]+"\t"+dvdstr[i][4]);            }            break;        case 4:            System.out.println("借出DVD");            if(dvdstr[0][2]==null){                System.out.println("庫存還沒有DVD,無法進行借出操作");                break;            }            System.out.print("請輸入DVD的名字:");            name = input.nextLine();            boolean b = false;            for(int i=0; i<6; i++){                if(dvdstr[i][2]!=null&&name.equals(dvdstr[i][2])){                    if("未借出".equals(dvdstr[i][1])) {                        System.out.print("請輸入借出日期:");                        int date = 0;                        do {                            date = in.nextInt();                        } while (date>31&&date<=0);                        dvdstr[i][1] = "已借出";                        dvdstr[i][3] = ""+date;                        dvdstr[i][4] = ""+(Integer.parseInt(dvdstr[i][4])+1);                        System.out.println("借出操作完成");                    }else{                        System.out.println("該DVD已被借出");                    }                    b = true;                    break;                }            }            if(!b){                System.out.println("該DVD不存在");            }            break;        case 5:            System.out.println("歸還DVD");            if(dvdstr[0][2]==null){                System.out.println("庫存還沒有DVD,無法進行歸還操作");                break;            }            System.out.print("請輸入DVD的名字:");            name = input.nextLine();            boolean flag = false;            for(int i=0; i<6; i++){                if(dvdstr[i][2]!=null&&name.equals(dvdstr[i][2])){                    if("已借出".equals(dvdstr[i][1])) {                        System.out.print("請輸入歸還日期:");                        int date = 0;                        int lend = Integer.parseInt(dvdstr[i][3]);                        do {                            date = in.nextInt();                        } while (date>31&&date<=0&&date>=lend);                        dvdstr[i][1] = "未借出";                        dvdstr[i][3] = null;                        System.out.println("歸還操作完成");                        System.out.println("借出日期:"+lend);                        System.out.println("歸還日期:"+date);                        System.out.println("您一共需要支付租金:"+((date-lend)*5)+"元");                    }else{                        System.out.println("該DVD已被借出");                    }                    flag = true;                    break;                }            }            if(!flag){                System.out.println("該DVD不存在");            }            break;        default:            System.out.println("您輸入的命令不合法!");            break;        }    }}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.