求各位大神用一个数组帮我完善下下! 有很多BUG
package dvd;
public class Menu {
public void menu(){
System.out.println("*********欢迎使用迷你DVD管理器************\n");
System.out.println("\t1.新增DVD");
System.out.println("\t2.查看DVD");
System.out.println("\t3.删除DVD");
System.out.println("\t4.借出DVD");
System.out.println("\t5.归还DVD");
System.out.println("\t6.退 出");
System.out.println("*******************************************");
}
}
package dvd;
public class test {
/**
* @param args
*/
public static void main(String[] args) {
DVDMgr mgr=new DVDMgr();
mgr.caidan();
}
}
package dvd;
public class DVDSet {
String[] name=new String[50];
int[] state=new int[50];
String[] date=new String[50];
}
package dvd;
import java.util.*;
public class DVDMgr {
Menu cc = new Menu();
Scanner input = new Scanner(System.in);
DVDSet dvd = new DVDSet();
String name;
boolean as = false;
public void caidan() {
cc.menu();
System.out.print("请选择:");
int num = input.nextInt();
if (num == 1) {
addDVD();
} else if (num == 2) {
searchDVD();
} else if (num == 3) {
deleteDVD();
} else if (num == 4) {
lendDVD();
} else if (num == 5) {
returnDVD();
} else if(num==6){
System.out.println("已退出,欢迎下次使用!");
return;
}
}
public void addDVD() {
System.out.println("------>新增DVD\n");
System.out.print("请输入DVD名称:");
name = input.next();
for (int i = 0; i < dvd.name.length; i++) {
if (dvd.name[i] == null) {
dvd.name[i] = name;
System.out.println("新增《 " + name + " 》成功");
break;
}
}
System.out.println("******************************************");
System.out.print("输入0返回:");
int fh = input.nextInt();
if (fh == 0) {
caidan();
}
}
public void searchDVD() {
System.out.println("-------->查看DVD\n");
initial();
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] == 1) {
System.out.println((i + 1) + "\t已借出\t" + "<<" + dvd.name[i]
+ ">>\t" + dvd.date[i]);
} else if (dvd.state[i] == 0) {
System.out.println((i + 1) + "\t可借\t" + "<<" + dvd.name[i]
+ ">>");
}
}
System.out.println("**************************************");
System.out.print("输入0返回:");
int fh = input.nextInt();
if (fh == 0) {
caidan();
}
}
private void initial() {
}
public void deleteDVD() {
System.out.println("------>删除DVD\n");
System.out.print("请输入DVD名称:");
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] == 0)) {
int g = i;
while (dvd.name[g + 1] != null) {
dvd.name[g] = dvd.name[g + 1];
dvd.state[g] = dvd.state[g + 1];
dvd.date[g] = dvd.date[g + 1];
g++;
}
dvd.name[g] = null;
dvd.date[g] = null;
System.out.println("刪除《" + name + "》成功!");
as = true;
break;
} else if (dvd.name[i] != null
&& dvd.name[i].equalsIgnoreCase(name) && dvd.state[i] == 0) {
System.out.println("<<" + name + ">>借出状态,不能删除!");
as = true;
break;
}
}
System.out.println("******************************************");
System.out.print("输入0返回:");
int fh = input.nextInt();
if (fh == 0) {
caidan();
} else {
System.out.println("输入错误,程序结束!");
}
}
public void lendDVD() {
System.out.println("------->借出DVD\n");
System.out.print("请输入DVD名称:");
name = 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(name) && dvd.state[i] == 0) {
System.out.println("找到匹配,可以借出");
System.out.println("请输入借出日期:");
dvd.date[i] = input.next();
System.out.println("借出《" + name + "》成功");
break;
} else if (dvd.name[i].equals(name) && dvd.state[i] == 1) {
System.out.println("找到匹配,已被借出!");
break;
}
}
System.out.println("******************************************");
System.out.print("输入0返回:");
int fh = input.nextInt();
if (fh == 0) {
caidan();
} else {
System.out.println("输入错误,程序结束!");
}
}
public void returnDVD() {
String dstr1;
String dstr2;
System.out.println("------>归还DVD\n");
System.out.print("请输入DVD名称:");
name = input.next();
for (int i = 0; i < dvd.name.length; i++) {
if (dvd.name[i] != null) {
if (dvd.name[i].equals(name)) {
if (dvd.state[i] == 0) {
System.out.print("请输入归还日期(年-月-日):");
dstr1 = input.next();
} else {
System.out.println("本店此书未被借出!");
}
}
}
}
System.out.println("******************************************");
System.out.print("输入0返回:");
int fh = input.nextInt();
if (fh == 0) {
caidan();
} else {
System.out.println("输入错误,程序结束!");
}
}
}
[ 本帖最后由 liuxinghuao 于 2012-8-11 22:14 编辑 ]