一个DVD管理系统
1:DVD类
package com;
public class Dvd {
String name;
String zhuangTai;
int time;
int ciShu;
}
2:DVD管理类
package com;
import java.util.Scanner;
public class DvdManage {
Scanner input = new Scanner(System.in);
Dvd dvd[] =new Dvd[6];
//查看DVD
public void chaKanDvd(){
System.out.println("名称\t"+"状态\t"+"借阅时间\t"+"借阅次数\t");
for(int i=0;i<dvd.length;i++){
System.out.println(dvd[i].name+"\t"+dvd[i].zhuangTai+"\t"+dvd[i].time+"\t"+dvd[i].ciShu);
}
}
//新增DVD
public boolean addDvd(Dvd x){
boolean b=false;
for(int i=0;i<dvd.length;i++){
if(dvd[i]==x){
System.out.println("新增失败,该dvd已经存在!");
break;
}
if(dvd[i]==null){
System.out.println("新增dvd成功!");
b=true;
dvd[i].name=x.name;
dvd[i].zhuangTai="未借阅";
dvd[i].ciShu=0;
}
if(dvd[5]!=null){
System.out.println("新增失败,dvd已满!");
break;
}
}
return b;
}
//删除DVD
public boolean deleteDvd(Dvd x){
boolean b=false;
for(int i=0;i<dvd.length;i++){
if(dvd[i].name==x.name){
dvd[i]=null;
b=true;
System.out.println("删除DVD成功!");
break;
}else{
System.out.println("该DVD不存在!");
}
}
return b;
}
//借阅DVD
public boolean jieYueDvd(Dvd x){
boolean b=false;
for(int i=0;i<dvd.length;i++){
if(dvd[i].name==x.name&&dvd[i].zhuangTai.equals("未借阅")){
dvd[i].zhuangTai="已借阅";
dvd[i].ciShu=dvd[i].ciShu+1;
System.out.print("请输入借阅时间:");
dvd[i].time=input.nextInt();
System.out.println("借阅成功!");
b=true;
break;
}
if(dvd[i].name==x.name&&dvd[i].zhuangTai.equals("已借阅")){
System.out.println("抱歉,该DVD已被借阅!");
}else{
System.out.println("该DVD不存在!");
}
}
return b;
}
//归还DVD
public boolean guiHuanDvd(Dvd x){
boolean b=false;
for(int i=0;i<dvd.length;i++){
if(dvd[i].name==x.name){
dvd[i].zhuangTai="未借阅";
dvd[i].time=0;
System.out.println("归还DVD成功!");
b=true;
break;
}
else{
System.out.println("该DVD不存在!");
}
}
return b;
}
}
3:DVD测试类
package com;
import java.util.Scanner;
public class DvdText {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
DvdManage dvd = new DvdManage();
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.退出DVD");
System.out.println("**********************************");
System.out.print("请选择功能:");
O:while(true){
int i = input.nextInt();
switch (i) {
case 1:
dvd.chaKanDvd();
break;
case 2:
Dvd dvd1=new Dvd();
dvd1.name=input.next();
dvd.addDvd(dvd1);
break;
case 3:
Dvd dvd2= new Dvd();
dvd2.name=input.next();
dvd.deleteDvd(dvd2);
break;
case 4:
Dvd dvd3 = new Dvd();
dvd3.name=input.next();
dvd.jieYueDvd(dvd3);
break;
case 5:
Dvd dvd4=new Dvd();
dvd4.name=input.next();
dvd.guiHuanDvd(dvd4);
break;
case 6:
System.out.println("感谢使用!");
break O;
default:
break;
}
}
}
}
写完了 ,代码没语法上的错误,可是DVD管理的6个功能却实现不了,看了好久,有没有兄弟愿意找下问题 。。