package July20th;
import java.util.Scanner;
public class Dvdmain {
@SuppressWarnings("resource")
public static void main(String[] args) {
// TODO Auto-generated method stub
Dvdshow shDvdshow = new Dvdshow();
shDvdshow.init();
Scanner input = new Scanner(System.in) ;
int choose = 0;
boolean flag = true;
do {
shDvdshow.showMainMenu();
choose = input.nextInt();
switch (choose) {
case 1:
shDvdshow.one();
break;
case 2:
shDvdshow.two();
break;
case 3:
shDvdshow.three();
break;
case 4:
shDvdshow.four();
break;
case 5:
shDvdshow.five();
break;
case 6:
shDvdshow.six();
break;
default:
break;
}
System.out.println("是否继续操作(Y/N)");
String yn = input.next();
if ("y".equalsIgnoreCase(yn)) {
flag = true;
continue;
}
flag = false ;
}while(flag);
System.out.println("欢迎下次使用,谢谢。");
}
}
package July20th;
import java.util.Scanner;
public class Dvdshow {
String [] names=new String[6];//存放电影名
double [] rental=new double[6];//存放DVD的价格;
boolean [] isborrow=new boolean[6];//存放是否借出;
String [] releaseTime=new String[6];
Scanner input;
/*
* 初始化系统数据
*/
public void init() {
// TODO Auto-generated method stub
names[0]="有一个地方";
rental[0]=20.8;
isborrow[0]=false;
releaseTime[0]="2018-6-5";
names[1]="机器人总动员";
rental[1]=10.9;
isborrow[1]=false;
releaseTime[1]="2017-6-5";
names[2]="复仇者联盟2";
rental[2]=38.9;
isborrow[2]=false;
releaseTime[2]="2019-12-5";
names[3]="钢铁侠";
rental[3]=29.3;
isborrow[3]=false;
releaseTime[3]="2018-5-5";
names[4]="功夫熊猫";
rental[4]=28;
isborrow[4]=false;
releaseTime[4]="2016-6-5";
}
/*
* 系统主菜单
*/
public void showMainMenu(){
System.out.println("欢迎使用DVD租用系统");
System.out.println("请选择您需要操作");
System.out.println("1:查看所有电影");
System.out.println("2:新增电影");
System.out.println("3:借出电影");
System.out.println("4:归还电影");
System.out.println("5:删除电影");
System.out.println("6:删除所有电影");
System.out.print("请输入您的操作序号:");
}
/*
* 查看所有电影
*/
public void one() {
// TODO Auto-generated method stub
System.out.println("==查看所有电影==");
System.out.println("电影名\t电影租金\t上映时间\t\t租借状态");
for(int i=0;i<names.length;i++){
//去掉末尾的空格
if(names[i]!=null&&!"".equals(names[i].trim())){
System.out.println(names[i]+"\t"+rental[i]+"\t"+releaseTime[i]+"\t"+(isborrow[i]==true?"借出":"未借出"));
}
}
}
/*
* 新增电影
*/
public void two() {
// TODO Auto-generated method stub
input=new Scanner(System.in);
System.out.println("==新增电影==");
//赋值部分
int index =-1;
for(int i=0;i<names.length;i++){
if(names[i]==null){
index=i;
break;
}
}
if(index!=-1){
System.out.println("请输入新增电影名");
String newName=input.next();
System.out.println("请输入租金");
double newRental=input.nextDouble();
System.out.println("请输入上映时间");
String newReleaseTime=input.next();
names[index]=newName;
rental[index]=newRental;
releaseTime[index]=newReleaseTime;
isborrow[index]=false;
System.out.println("录入成功");
}else{
System.out.println("磁盘已满,无法录入");
}
}
/*
* 借出电影
*/
public void three() {
// TODO Auto-generated method stub
input=new Scanner(System.in);
System.out.println("==借出电影==");
System.out.println("您可以租借如下电影:");
System.out.println("电影序号\t电影名\t电影租金\t上映时间\t租借状态");
for(int i=0;i<names.length;i++){
if(isborrow[i]!=true&&names[i]!=null&&!"".equals(names[i].trim())){
System.out.println((i+1)+"\t"+names[i]+"\t"+rental[i]+"\t"+releaseTime[i]+"\t\t"+(isborrow[i]==true?"借出":"未借出"));
}
}
System.out.println("请选择你要租借的电影");
int choose=input.nextInt();
isborrow[choose-1]=true;
System.out.println("请输入租借的天数");
int day=input.nextInt();
switch (choose) {
case 1:
System.out.println("电影信息:"+names[0]+"\t租金合计:"+day*rental[0]+"元");
break;
case 2:
System.out.println("电影信息"+names[1]+"\t租金合计:"+day*rental[1]+"元");
break;
case 3:
System.out.println("电影信息"+names[2]+"\t租金合计:"+day*rental[2]+"元");
break;
case 4:
System.out.println("电影信息"+names[3]+"\t租金合计:"+day*rental[3]+"元");
break;
case 5:
System.out.println("电影信息"+names[4]+"\t租金合计:"+day*rental[4]+"元");
break;
case 6:
System.out.println("电影信息"+names[5]+"\t租金合计:"+day*rental[5]+"元");
break;
default:
break;
}
}
/*
* 归还电影
*/
public void four() {
// TODO Auto-generated method stub
input=new Scanner(System.in);
System.out.println("==归还电影==");
System.out.println("请输入归还的电影名称:");
String rebackname=input.next();
for(int i=0;i<names.length;i++){
if(rebackname.equals(names[i])){
isborrow[i]=false;
}
}
System.out.println("归还成功");
}
/*
* 删除电影
*/
public void five() {
// TODO Auto-generated method stub
input=new Scanner(System.in);
System.out.println("==删除电影==");
System.out.println("请选择删除的电影");
for(int i=0;i<names.length;i++){
if(names[i]!=null&&!"".equals(names[i].trim())){
System.out.println((i+1)+"\t"+names[i]+"\t"+rental[i]+"\t"+releaseTime[i]+"\t"+(isborrow[i]==true?"借出":"未借出"));
}
}
int choose=input.nextInt();
for(int i=0;i<names.length-1;i++){
if(i<choose-1){
names[i]=names[i];
rental[i]=rental[i];
releaseTime[i]=releaseTime[i];
isborrow[i]=isborrow[i];
}else {
names[i]=names[i+1];
rental[i]=rental[i+1];
releaseTime[i]=releaseTime[i+1];
isborrow[i]=isborrow[i+1];
}
}
names[names.length-1]=null;
rental[names.length-1]=0.0;
releaseTime[names.length-1]=null;
isborrow[names.length-1]=false;
System.out.println("删除成功!");
}
/*
* 删除所有电影
*/
public void six() {
// TODO Auto-generated method stub
System.out.println("==删除所有电影==");
for(int i=0;i<names.length;i++){
names[i]=null;
rental[i]=0.0;
releaseTime[i]=null;
isborrow[i]=false;
}
System.out.println("删除成功");
}
}