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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

迷你DVD管理器项目

發(fā)布時間:2025/4/14 编程问答 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 迷你DVD管理器项目 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
1 package chapter5; 2 import java.util.*; 3 4 public class MiniDVD { 5 public static void main(String[] args){ 6 //掃描器 7 Scanner input = new Scanner(System.in); 8 //重要參數(shù)及初始化 9 //Create four arrays with length of 7 10 //定義四個數(shù)組長度為7 11 int date[] = new int[7]; //borrow date 12 int count[] = new int[7]; //total count 13 String name[] =new String[7]; //name of DVDs 14 String state[] = new String[7]; //state 15 //Initiate three DVD 16 //FirstDVD 17 name[0] = "羅馬假日"; 18 state[0] = "已借出"; 19 date[0] = 1; 20 count[0] =15; 21 //Second DVD 22 name[1] = "風聲鶴唳"; 23 state[1] = "可借"; 24 date[1] = 0; 25 count[1] =12; 26 //Third DVD 27 name[2] = "浪漫滿屋"; 28 state[2] = "可借"; 29 date[2] = 0; 30 count[2] =30; 31 32 //循環(huán)進入條件 33 String choice = " "; 34 boolean flag = true; 35 do{ 36 //Create DVD Menu 37 System.out.println("歡迎使用迷你DVD管理器"); 38 System.out.println("------------------------------------------------------"); 39 System.out.println("1.新增DVD"); 40 System.out.println("2.查看DVD"); 41 System.out.println("3.刪除DVD"); 42 System.out.println("4.借出DVD"); 43 System.out.println("5.歸還DVD"); 44 System.out.println("6.退出DVD"); 45 System.out.println("------------------------------------------------------"); 46 System.out.print("請選擇:"); 47 choice = input.next(); 48 49 //Switch choice menu 50 switch (choice){ 51 case "1": 52 System.out.println("--->新增DVD"); 53 System.out.print("\n請輸入DVD名稱:"); 54 boolean firstMonitor = true; 55 boolean secondMonitor = false; 56 String bookName = " "; 57 do{ 58 bookName= input.next(); 59 if(firstMonitor){ 60 for(int i = 0; i<name.length; i++){ 61 if(bookName.equals(name[i])){ 62 System.out.println("貨架上已經(jīng)存在該DVD,請返回目錄重新選擇!"); 63 secondMonitor = true; 64 break; 65 } 66 } 67 } 68 firstMonitor =false; 69 }while(firstMonitor); 70 71 if(!secondMonitor){ 72 for (int j = 0;j<name.length; j++){ 73 if((name[j])==null){ 74 name[j]= bookName; 75 state[j] = "可借"; 76 count[j] = 0; 77 System.out.println("新增《"+bookName+"》成功!"); 78 System.out.println("***************************"); 79 break; 80 } 81 if(name[name.length-2] !=null){ 82 System.out.println("DVD貨架已滿,添加失敗!"); 83 System.out.println("***************************"); 84 break; 85 } 86 } 87 } 88 break; 89 case "2": 90 System.out.println("--->查看DVD"); 91 System.out.println("序號\t狀態(tài)\t名稱\t\t借出日期\t借出次數(shù)"); 92 for (int i = 0; i<name.length; i++){ 93 if(name[i] == null){ 94 System.out.println("***************************"); 95 break; 96 } 97 String myDate = " "; 98 if(date[i] != 0){ 99 myDate = date[i]+"日"; 100 } 101 System.out.println((i+1)+"\t"+state[i]+"\t"+"《"+name[i]+"》"+"\t"+myDate+"\t"+count[i]+"次"); 102 } 103 break; 104 case "3": 105 System.out.println("--->刪除DVD"); 106 System.out.print("\n請輸入DVD名稱:"); 107 String delName = input.next(); 108 //define index monitor: check 109 int check = -1; 110 for(int i = 0; i < name.length; i++){ 111 if(delName.equals(name[i])){ 112 check = i; 113 break; 114 } 115 } 116 if(check != -1){ 117 if(state[check].equals("可借")){ 118 //Delete operation 119 for(int j = check; j < name.length-1; j++){ 120 name[j] = name[j+1]; 121 state[j] = state[j+1]; 122 date[j] = date[j+1]; 123 count[j] = count[j+1]; 124 } 125 System.out.println("刪除《"+delName+"》成功!"); 126 System.out.println("***************************"); 127 break; 128 }else{ 129 System.out.println("DVD為借出狀態(tài),不允許刪除!"); 130 System.out.println("***************************"); 131 } 132 }else{ 133 System.out.println("沒有找到匹配信息!"); 134 System.out.println("***************************"); 135 } 136 break; 137 case "4": 138 System.out.println("--->借出DVD"); 139 System.out.print("\n請輸入DVD名稱:"); 140 String lendName = input.next(); 141 //Initiate lendDate with 1, so as to enter the do-loop 142 int lendDate = 1; 143 System.out.print("請輸入借出日期:"); 144 //Avoid user input wrong date 145 do{ 146 lendDate = input.nextInt(); 147 if((lendDate<1)||(lendDate>31)){ 148 System.out.print("必須輸入大于等于1且小于等于31的數(shù)字,請重新輸入:"); 149 } 150 }while((lendDate<1)||(lendDate>31)); 151 152 //define index monitor 153 int index = -1; 154 for(int i = 0; i < name.length; i++){ 155 if(lendName.equals(name[i])){ 156 index = i; 157 break; 158 } 159 160 } 161 //lend operation 162 if(index != -1){ 163 if(state[index].equals("可借")){ 164 state[index] = "已借出"; 165 count[index] +=1; 166 date[index] = lendDate; 167 System.out.println("借出《"+lendName+"》成功!"); 168 System.out.println("***************************"); 169 }else{ 170 System.out.println("《"+lendName+"》已被借出!"); 171 System.out.println("***************************"); 172 } 173 }else{ 174 System.out.println("沒有找到匹配信息!"); 175 System.out.println("***************************"); 176 } 177 break; 178 case "5": 179 System.out.println("--->歸還DVD"); 180 System.out.print("\n請輸入DVD名稱:"); 181 String returnName = input.next(); 182 //define index monitor 183 int monitor = -1; 184 for(int i = 0; i < name.length; i++){ 185 if(returnName.equals(name[i])){ 186 monitor = i; 187 break; 188 } 189 190 } 191 //Initiate myLendPeriod with 0, and enter the do-loop 192 int returnDate = 0; 193 int myLendPeriod = 0; 194 do{ 195 System.out.print("請輸入歸還日期:"); 196 //Avoid user input wrong date 197 do{ 198 returnDate = input.nextInt(); 199 if(monitor != -1){ 200 myLendPeriod = returnDate - date[monitor]; 201 } 202 if(returnDate > 31){ 203 System.out.print("一個月只有31天,請重新輸入:"); 204 } 205 if(myLendPeriod < 0){ 206 System.out.println("歸還日期不能小于借出日期,請重新輸入:"); 207 } 208 }while((returnDate>31)||(myLendPeriod<0)); 209 //Return operation 210 if(monitor != -1){ 211 if(state[monitor].equals("已借出")){ 212 state[monitor] = "可借"; 213 date[monitor] = 0; 214 System.out.println("歸還《"+returnName+"》成功!"); 215 System.out.println("借出日期為:"+date[monitor]+"日"); 216 System.out.println("歸還日期為:"+returnDate+"日"); 217 System.out.println("應付租金(元):"+myLendPeriod); 218 System.out.println("***************************"); 219 }else{ 220 System.out.println("該DVD沒有被借出!無法進行歸還操作。"); 221 System.out.println("***************************"); 222 } 223 }else{ 224 System.out.println("沒有找到匹配信息!"); 225 System.out.println("***************************"); 226 } 227 break; 228 }while(myLendPeriod < 0); 229 break; 230 case "6": 231 flag = false; 232 break; 233 default: 234 } 235 if(flag){ 236 System.out.print("輸入任意值返回:"); 237 choice = input.next(); 238 } 239 }while(flag); 240 241 //program exit 242 System.out.println("程序結束"); 243 } 244 }

?

轉(zhuǎn)載于:https://www.cnblogs.com/WuXuanKun/p/5417016.html

總結

以上是生活随笔為你收集整理的迷你DVD管理器项目的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

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