java项目DVD
package com.BLL;
//声明数组 好使用对象数组
public class DVDSet {
String[] name=new String[50]; //数组1储存名称
int[] state=new int[50]; //数组2DvD借出状态0已借出
String[] date=new String[50];//数组3储存DVD借出日期
int [] count = new int[50];//同一本书借出次数
String[] riqi = new String[50];
int[] zht = new int[50];
}
package com.BLL;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;
public class DVDMgr {
//创建DVD对象
public static DVDSet dvd=new DVDSet();
String time1;//借出日期
String time2;//归还日期
private int j;
public void dvdMgr(){
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);
System.out.println("欢迎进入新增DVD");
System.out.print("请输入DVD名称:");
String name=input.next();
for (int i = 0; i < dvd.name.length; i++) {
if (dvd.name[i]==null) {
dvd.name[i]=name;
dvd.state[i]=1;
System.out.println("新增成功!");
break;
}
}
}
//4.查看的功能
public void searchDVD(){
System.out.println("******欢迎进入查看页面*****");
//\t Tap
System.out.println("序号\t名称\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]+">>");
}
}
}
//实现删除DVD信息
public void delete(){
boolean flag;
Scanner input=new Scanner(System.in);
System.out.println("欢迎进入删除DVD");
System.out.print("请输入DVD名称:");
String name=input.next();
for(int i=0;i<dvd.name.length;i++){
if(dvd.name[i]!=null&& dvd.name[i].equalsIgnoreCase(name)&&dvd.state[i]==1){
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("删除<<"+name+">>成功");
flag=true; //标识位
break;
}else if (dvd.name[i]!=null&&dvd.name[i].equalsIgnoreCase(name)&&dvd.state[i]==0) {
System.out.println("《"+name+"》为借出状态,不能删除!");
flag=true; //标识符
break;
}
}
}
//实现借出DVD
public void lend(){
int k = 0;
dvd.count[k]=0;
System.out.println("欢迎进入借出DVD");
System.out.print("请输入借出DVD名称:");
Scanner input=new Scanner(System.in);
String want=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(want)&&dvd.state[i]==1) {
//找到匹配可借
System.out.print("你成功借到《"+want+"》");
System.out.print("请输入借出日期:");
time1=input.next();
//记录借出日期
dvd.state[i]=0;
dvd.count[i]++;
break;
}else if(dvd.name[i].equals(want)&&dvd.state[i]==0){
System.out.println("找到匹配信息,已被借出!");
break;
}
}
}
/**
* 归还DVD
*/
public void charge() {
Scanner input=new Scanner(System.in);
System.out.println("请输入归还的DVD名称:");
String a = input.next();
for (int i = 0; i < dvd.name.length; i++) {
if (dvd.name[i] == null) {
break;
} else if (dvd.name[i].equals(a) && dvd.state[i]==0) {
System.out.println("请输入归还日期:");
String riqi = input.next();
dvd.state[i]=1;
/*dvd.count[i]++;*/
System.out.println("归还成功!");
break;
} else if (dvd.name[i].equalsIgnoreCase(a) && dvd.state[i] == 1) {
System.out.println("DVD状态为 可借,无法归还!");
break;
}
}
}
}
//测试类
public class Test02 {
public static void main(String[] args) {
startMenu lx=new startMenu();
lx.startMenu();
}
}