import java.util.*;
import java.text.*;
public class MiniDVD {
public static void main(String[] args){
DVDMgr mgr= new DVDMgr();
mgr.initial();
mgr.startmenu();
}
}
class DVDSet{
String[] name=new String[50];
int[] state= new int[50];
String[] date=new String[50];
}
class DVDMgr{
DVDSet dvd=new DVDSet();
public void initial(){
dvd.name[0]="罗马假日";
dvd.state[0]=0;
dvd.date[0]="2012-2-1";
dvd.name[1]="风声鹤唳";
dvd.state[1]=1;
dvd.name[2]="浪漫满屋 ";
dvd.state[2]=1;
System.out.println("name\t\tstate\t\tdate");
System.out.println(dvd.name[0]+"\t\t"+dvd.state[0]+"\t\t"+dvd.date[0]);
System.out.println(dvd.name[1]+"\t\t"+dvd.state[1]+"\t\t"+dvd.date[1]);
System.out.println(dvd.name[2]+"\t\t"+dvd.state[2]+"\t\t"+dvd.date[2]);
}
public void startmenu(){
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. 退出");
System.out.println("---------------------------");
System.out.println("请选择:");
int choice=input.nextInt();
switch(choice){
case 1:
System.out.println("此处实现新增DVD");
System.out.println("***************************");
add();
returnmain();
break;
case 2:
System.out.println("此处实现查看DVD");
System.out.println("***************************");
search();
returnmain();
break;
case 3:
System.out.println("此处实现删除DVD");
System.out.println("***************************");
delete();
returnmain();
break;
case 4:
System.out.println("此处实现借出DVD");
System.out.println("***************************");
lend();
returnmain();
break;
case 5:
System.out.println("此处实现归还DVD");
System.out.println("***************************");
returnDvd();
returnmain();
break;
}
}
public void returnmain(){
Scanner input = new Scanner(System.in);
System.out.println("输入0返回");
if(input.nextInt()==0){
startmenu();
}else{
System.out.println("输入错误,异常中止");
}
}
public void search(){
System.out.println("序号\t状态\t名称\t借出日期");
for(int i=0;i<dvd.name.length;i++){
if(dvd.name[i]==null){
break;
}else if(dvd.state[i]==0){
System.out.println((i+1)+"\t已借出\t"+"《"+dvd.name[i]+"》\t"+dvd.date[i]);
}else if(dvd.state[i]==1){
System.out.println((i+1)+"\t可借\t"+"《"+dvd.name[i]+"》\t"+dvd.date[i]);
}
}
}
public void add(){
Scanner input = new Scanner(System.in);
System.out.println("请输入DVD名称:");
String book = input.next();
boolean flag=false;
for(int i=0;i<dvd.name.length;i++){
if(dvd.name[i]==null){
dvd.name[i]=book;
dvd.state[i]=1;
flag=true;
break;
}
}
if(flag){
System.out.println("新增"+"《"+book+"》成功!");
}else{
System.out.println("货架已满,不能新增。");
}
}
public void delete(){
Scanner input = new Scanner(System.in);
System.out.println("请输入DVD名称:");
String book =input.next();
for(int i=0;i<dvd.name.length;i++){
if(dvd.name[i]!=null&&dvd.state[i]==1&&dvd.name[i].equals(book)){
int j=i;
while(dvd.name[j+1]!=null){
dvd.name[j]=dvd.name[j+1];
dvd.state[j]=dvd.state[j+1];
dvd.date[j]=dvd.date[j+1];
j++;
}
dvd.name[j]=null;
dvd.date[j]=null;
System.out.println("删除《"+book+"》成功!");
break;
}else if(dvd.name[i]!=null&&dvd.state[i]==0&&dvd.name[i].equals(book)){
System.out.println("《"+book+"》为借出状态,不能删除");
break;
}
}
}
public void lend(){
Scanner input = new Scanner(System.in);
System.out.println("请输入DVD名称:");
String book =input.next();
for(int i=0;i<dvd.name.length;i++){
if(dvd.name[i]==null){
System.out.println("没有找到匹配信息!");
break;
}else if(dvd.name[i].equals(book)&&dvd.state[i]==1){
dvd.state[i]=0;
System.out.println("请输入借书日期(年/月/日):");
dvd.date[i]=input.next();
System.out.println("借出《"+book+"》成功");
break;
}else if(dvd.name[i].equals(book)&&dvd.state[i]==0){
System.out.println("《"+book+"》已被借出");
break;
}
}
}
public void returnDvd(){
Scanner input = new Scanner(System.in);
System.out.println("请输入DVD名称:");
String book =input.next();
for(int i=0;i<dvd.name.length;i++){
if(dvd.name[i]==null){
System.out.println("没有找到匹配信息");
break;
}else if(dvd.name[i].equals(book)&&dvd.state[i]==1){
System.out.println("这本书没有借出");
break;
}else if(dvd.name[i].equals(book)&&dvd.state[i]==0){
dvd.state[i]=1;
System.out.println("请输入归还日期(年/月/日):");
String date=input.next();
System.out.println("归还《"+book+"》成功!");
System.out.println("借出日期为:"+dvd.date[i]);
System.out.println("归还日期为:"+date);
System.out.println("应付租金(元)为:"+DVDMgr.charge(dvd.date[i],date));
break;
}
}
}
public static long charge(String dstr1,String dstr2){
long charge=0;
SimpleDateFormat sd=new SimpleDateFormat("yyyy-MM-dd");
try {
Date d1=sd.parse(dstr1);
Date d2=sd.parse(dstr2);
charge=(d2.getTime()-d1.getTime())/(24*60*60*1000);
} catch (ParseException e) {
e.printStackTrace();
}
return charge;
}
}
import java.text.*;
public class MiniDVD {
public static void main(String[] args){
DVDMgr mgr= new DVDMgr();
mgr.initial();
mgr.startmenu();
}
}
class DVDSet{
String[] name=new String[50];
int[] state= new int[50];
String[] date=new String[50];
}
class DVDMgr{
DVDSet dvd=new DVDSet();
public void initial(){
dvd.name[0]="罗马假日";
dvd.state[0]=0;
dvd.date[0]="2012-2-1";
dvd.name[1]="风声鹤唳";
dvd.state[1]=1;
dvd.name[2]="浪漫满屋 ";
dvd.state[2]=1;
System.out.println("name\t\tstate\t\tdate");
System.out.println(dvd.name[0]+"\t\t"+dvd.state[0]+"\t\t"+dvd.date[0]);
System.out.println(dvd.name[1]+"\t\t"+dvd.state[1]+"\t\t"+dvd.date[1]);
System.out.println(dvd.name[2]+"\t\t"+dvd.state[2]+"\t\t"+dvd.date[2]);
}
public void startmenu(){
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. 退出");
System.out.println("---------------------------");
System.out.println("请选择:");
int choice=input.nextInt();
switch(choice){
case 1:
System.out.println("此处实现新增DVD");
System.out.println("***************************");
add();
returnmain();
break;
case 2:
System.out.println("此处实现查看DVD");
System.out.println("***************************");
search();
returnmain();
break;
case 3:
System.out.println("此处实现删除DVD");
System.out.println("***************************");
delete();
returnmain();
break;
case 4:
System.out.println("此处实现借出DVD");
System.out.println("***************************");
lend();
returnmain();
break;
case 5:
System.out.println("此处实现归还DVD");
System.out.println("***************************");
returnDvd();
returnmain();
break;
}
}
public void returnmain(){
Scanner input = new Scanner(System.in);
System.out.println("输入0返回");
if(input.nextInt()==0){
startmenu();
}else{
System.out.println("输入错误,异常中止");
}
}
public void search(){
System.out.println("序号\t状态\t名称\t借出日期");
for(int i=0;i<dvd.name.length;i++){
if(dvd.name[i]==null){
break;
}else if(dvd.state[i]==0){
System.out.println((i+1)+"\t已借出\t"+"《"+dvd.name[i]+"》\t"+dvd.date[i]);
}else if(dvd.state[i]==1){
System.out.println((i+1)+"\t可借\t"+"《"+dvd.name[i]+"》\t"+dvd.date[i]);
}
}
}
public void add(){
Scanner input = new Scanner(System.in);
System.out.println("请输入DVD名称:");
String book = input.next();
boolean flag=false;
for(int i=0;i<dvd.name.length;i++){
if(dvd.name[i]==null){
dvd.name[i]=book;
dvd.state[i]=1;
flag=true;
break;
}
}
if(flag){
System.out.println("新增"+"《"+book+"》成功!");
}else{
System.out.println("货架已满,不能新增。");
}
}
public void delete(){
Scanner input = new Scanner(System.in);
System.out.println("请输入DVD名称:");
String book =input.next();
for(int i=0;i<dvd.name.length;i++){
if(dvd.name[i]!=null&&dvd.state[i]==1&&dvd.name[i].equals(book)){
int j=i;
while(dvd.name[j+1]!=null){
dvd.name[j]=dvd.name[j+1];
dvd.state[j]=dvd.state[j+1];
dvd.date[j]=dvd.date[j+1];
j++;
}
dvd.name[j]=null;
dvd.date[j]=null;
System.out.println("删除《"+book+"》成功!");
break;
}else if(dvd.name[i]!=null&&dvd.state[i]==0&&dvd.name[i].equals(book)){
System.out.println("《"+book+"》为借出状态,不能删除");
break;
}
}
}
public void lend(){
Scanner input = new Scanner(System.in);
System.out.println("请输入DVD名称:");
String book =input.next();
for(int i=0;i<dvd.name.length;i++){
if(dvd.name[i]==null){
System.out.println("没有找到匹配信息!");
break;
}else if(dvd.name[i].equals(book)&&dvd.state[i]==1){
dvd.state[i]=0;
System.out.println("请输入借书日期(年/月/日):");
dvd.date[i]=input.next();
System.out.println("借出《"+book+"》成功");
break;
}else if(dvd.name[i].equals(book)&&dvd.state[i]==0){
System.out.println("《"+book+"》已被借出");
break;
}
}
}
public void returnDvd(){
Scanner input = new Scanner(System.in);
System.out.println("请输入DVD名称:");
String book =input.next();
for(int i=0;i<dvd.name.length;i++){
if(dvd.name[i]==null){
System.out.println("没有找到匹配信息");
break;
}else if(dvd.name[i].equals(book)&&dvd.state[i]==1){
System.out.println("这本书没有借出");
break;
}else if(dvd.name[i].equals(book)&&dvd.state[i]==0){
dvd.state[i]=1;
System.out.println("请输入归还日期(年/月/日):");
String date=input.next();
System.out.println("归还《"+book+"》成功!");
System.out.println("借出日期为:"+dvd.date[i]);
System.out.println("归还日期为:"+date);
System.out.println("应付租金(元)为:"+DVDMgr.charge(dvd.date[i],date));
break;
}
}
}
public static long charge(String dstr1,String dstr2){
long charge=0;
SimpleDateFormat sd=new SimpleDateFormat("yyyy-MM-dd");
try {
Date d1=sd.parse(dstr1);
Date d2=sd.parse(dstr2);
charge=(d2.getTime()-d1.getTime())/(24*60*60*1000);
} catch (ParseException e) {
e.printStackTrace();
}
return charge;
}
}