import java.text.ParseException;
import java.util.Scanner;
public class Menu {
static DVDMgr mg=new DVDMgr();
public static void startMenu() throws ParseException {
int choose=0;
Scanner input=new Scanner(System.in);
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.退 出");
choose=input.nextInt();
switch(choose) {
case 1:
System.out.println("----->新增DVD");
mg.add();
returnMenu();
break;
case 2:
System.out.println("----->查看DVD");
mg.search();
returnMenu();
break;
case 3:
System.out.println("----->删除DVD");
mg.delete();
returnMenu();
break;
case 4:
System.out.println("----->借出DVD");
mg.rent();
returnMenu();
break;
case 5:
System.out.println("----->归还DVD");
mg.back();
returnMenu();
break;
case 6:
System.out.println("退出成功");
break;
default:
break;
}
}
public static void returnMenu() throws ParseException {
int flag=1;
Scanner input=new Scanner(System.in);
System.out.println("输入0返回");
flag=input.nextInt();
if(flag==0) {
startMenu();}
else {
System.out.println("退出成功");
}
}
public static void main(String[] args) throws ParseException {
mg.initial();
startMenu();
}
}
public class DVDset {
String[]name = new String[50];//DVD名称数组
int[]state = new int[50]; //DVD借出状态:0已借出,1可借
String[]date=new String[50]; //DVD借出日期
}
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;
public class DVDMgr {
DVDset dvd=new DVDset();
public int dvdnum=3;
public void initial() {
dvd.name[0]="罗马假日";
dvd.state[0]=0;
dvd.date[0]="2013-7-1";
dvd.name[1]="风声鹤唳";
dvd.state[1]=1;
dvd.name[2]="浪漫满屋";
dvd.state[2]=1;
}
public void add() {
Scanner input=new Scanner(System.in);
int j=0;
String name="";
System.out.println("");
System.out.println("输入DVD名称:");
name=input.next();
while(dvd.name[j]!=null) {
j++;
}
dvd.name[j]=name;
dvd.state[j]=1;
dvdnum++;
}
public void search() {
int i=0;
System.out.println("序号\t状态\t名称\t借出日期");
while(!(dvd.name[i]==null)) {
System.out.print((i+1)+"\t");
if(dvd.state[i]==1) {
System.out.println("可借\t"+dvd.name[i]);}
else {
System.out.println("已借出\t"+dvd.name[i]+"\t"+dvd.date[i]);
}
i++;
}
}
public void delete() {
String name="";
int j=0;
Scanner input=new Scanner(System.in);
System.out.println("请输入DVD名称:");
name=input.next();
while(!(dvd.name[j].equals(name))) {
j++;
}
if((j+1)>dvdnum) {
System.out.println("输入错误,未找到此DVD!");
}
if(dvd.state[j]==0) {
System.out.println("此DVD已经借出,无法删除");
}else {
for(int k=j;k<dvdnum;k++) {
dvd.name[k]=dvd.name[k+1];
dvd.state[k]=dvd.state[k+1];
dvd.date[k]=dvd.date[k+1];
}
System.out.println("删除《"+name+"》成功");
}
}
public void rent() {
Scanner input=new Scanner(System.in);
String name="";
String date="";
int j=0;
System.out.println("请输入要借的DVD:");
name=input.next();
System.out.println("请输入借出日期(年-月-日)");
date=input.next();
while(!(dvd.name[j].equals(name))) {
j++;
}
if(j>=dvdnum) {
System.out.println("未找到此书");
}else {
dvd.state[j]=0;
dvd.date[j]=date;
System.out.println("借出《"+name+"》成功");
}
}
public void back() throws ParseException {
Scanner input=new Scanner(System.in);
String name="";
String date="";
int j=0;
long money=0;
System.out.println("请输入归还DVD名称");
name=input.next();
System.out.println("请输入归还日期(年-月-日):");
date=input.next();
while(!(dvd.name[j].equals(name))) {
j++;
}
if(j>=dvdnum) {
System.out.println("未找到此书");
}
else {
System.out.println("归还《"+name+"》成功");
dvd.state[j]=1;
System.out.println("借出日期为"+dvd.date[j]);
System.out.println("归还日期为"+date);
SimpleDateFormat sd=new SimpleDateFormat("yyyy-MM-dd");
Date d1=sd.parse(dvd.date[j]);
Date d2=sd.parse(date);
money=(d2.getTime()-d1.getTime())/(24*60*60*1000);//得到日期差
System.out.println("应付租金(元)"+money);
}
}
}