package com.project; public class DVDSet { String[] name= new String[50]; int[] State=new int[50]; String[] date=new String[50]; }
package com.project; import java.sql.Date; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Scanner; public class DVDMgr { static DVDSet dvd=new DVDSet(); static Scanner input=new Scanner(System.in); public static void main(String[] args) { } public void initial() { dvd.name[0]="罗马假日"; dvd.name[1]="风声鹤唳"; dvd.name[2]="浪漫满屋"; dvd.State[0]=0; dvd.State[1]=1; dvd.State[2]=1; dvd.date[0]="2013-7-1"; } public void search() { System.out.println("序号\t"+"状态\t"+"名称\t\t"+"借出日期"); for(int i=0;dvd.name[i]!=null;i++) { int ii=i+1; System.out.print(ii+"\t"); if(dvd.State[i]==0) System.out.print("已借出"+"\t"); else System.out.print("可借"+"\t"); System.out.print(dvd.name[i]+"\t"+"\t"); System.out.println(dvd.date[i]); } } public void add() { int a = 0; String name; for(int i=0;i<=50;i++) { if(dvd.name[i]==null) { a=i; break; } } System.out.println("请输入DVD名称"); name=input.next(); dvd.name[a]=name; dvd.State[a]=1; System.out.println("新增"+dvd.name[a]+"成功!"); } public void delete() { System.out.println("请输入DVD名称"); String name; int b=0,i=0,n=3,a=0; name=input.next(); for(i=0;i<=49;i++) { if(dvd.name[i]!=null&&dvd.name[i].equalsIgnoreCase(name)&&dvd.State[i]==0) { System.out.println(dvd.name[i]+"为已借出状态,不能删除"); n=1; break; } else if(dvd.name[i]!=null&&dvd.name[i].equalsIgnoreCase(name)&&dvd.State[i]==1) { a=i; while(dvd.name[a+1]!=null) { dvd.name[a] = dvd.name[a+1]; dvd.State[a] = dvd.State[a+1]; dvd.date[a] = dvd.date[a+1]; a+=1; } dvd.name[a]=null; dvd.date[a]=null; System.out.println("DVD"+name+"删除成功"); n=1; break; } } if(n!=1) { System.out.println("无此书籍"); } } public void set() { System.out.println("请输入DVD名称"); String name,da; name=input.next(); int i=0,n=3; for(i=0;i<=49;i++) { if(dvd.name[i]!=null&&dvd.name[i].equalsIgnoreCase(name)&&dvd.State[i]==1) { System.out.println("请输入借出日期"); da=input.next(); System.out.println("DVD"+name+"借出成功"); dvd.State[i]=0; n=1; break; } else if(dvd.name[i]!=null&&dvd.name[i].equalsIgnoreCase(name)&&dvd.State[i]==0) { System.out.println(name+"已经借出"); n=1; break; } } if(n!=1) { System.out.println("未找到此DVD"); } } public void ret() { System.out.println("请输入DVD名称"); String name,returndate; name=input.next(); int i=0,n=0; long chargee; for(i=0;i<=49;i+=1) { if(dvd.name[i]!=null&&dvd.name[i].equalsIgnoreCase(name)&&dvd.State[i]==0) { System.out.println("请输入归还日期"); returndate=input.next(); System.out.println("归还"+name+"成功"); System.out.println("借出日期为"+dvd.date[i]); System.out.println("归还日期为"+returndate); chargee=charge(dvd.date[i],returndate); System.out.println("应付租金"+chargee); n=1; break; } else if(dvd.name[i]!=null&&dvd.name[i].equalsIgnoreCase(name)&&dvd.State[i]==1) { System.out.println("DVD"+name+"未借出,不需归还"); n=1; break; } } if(n!=1) System.out.println("未找到此DVD"); } public long charge(String dstr1, String dstr2) { long charge = 0; SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd"); // 格式化日期 try { java.util.Date d1 =sd.parse(dstr1); java.util.Date d2 =sd.parse(dstr2); charge = (d2.getTime() - d1.getTime()) / (24 * 60 * 60 * 1000); } catch (ParseException e) { //e.printStackTrace(); } return charge; } }
package com.project; import java.util.Scanner; public class Start { Scanner input=new Scanner(System.in); public static void main(String[] args) { Scanner input=new Scanner(System.in); DVDMgr mgr=new DVDMgr(); mgr.initial(); startMenu(); returnMain(); } public static void startMenu() { Scanner input=new Scanner(System.in); DVDMgr mgr=new DVDMgr(); System.out.println("欢迎使用迷你DVD管理器"); System.out.println("---------------------------------"); System.out.println("1. 新增DVD"); System.out.println("2. 查看DVD"); System.out.println("3. 删除DVD"); System.out.println("4. 借出DVD"); System.out.println("5. 归还DVD"); System.out.println("6. 退出"); System.out.println("---------------------------------"); System.out.println("请输入:"); int i=input.nextInt(); switch (i) { case 1: System.out.println("--->新增DVD"); mgr.add(); break; case 2: System.out.println("--->查看DVD"); mgr.search(); break; case 3: System.out.println("--->删除DVD"); mgr.delete(); break; case 4: System.out.println("--->借出DVD"); mgr.set(); break; case 5: System.out.println("--->归还DVD"); mgr.ret(); break; case 6: System.out.println("谢谢使用"); default: System.out.println("您的输入有误,请查看后再次输入!"); break; } } public static void returnMain() { Scanner input=new Scanner(System.in); System.out.println("输入0返回"); int i=input.nextInt(); if(i==0) startMenu(); returnMain(); } }