关闭

迷你DVD管理系统

标签: java源代码
878人阅读 评论(0) 收藏 举报
分类:

功能如下:

新增、查看、删除、借出、归还、退出。
之前修改了很多遍,重写了几次,但是至今没有发现为什么我之前的编译不出来,同时也没有明白后面为什么会成功完成全部功能。尴尬


源代码如下:





import java.util.Scanner;

public class Test {
	public static void main(String [] args){
		Scanner input = new Scanner(System.in);
		/*
		 * 借出状态、名称、日期、借出次数
		 */
		int index = -1;
		boolean [] status = new boolean [7];//借出状态
		String [] names = new String [7];//名称
		int [] data = new int [7];//日期
		int [] account = new int [7];//次数
		
		status [0] = false;
		names [0] = "罗马假日";
		data [0] = 1;
		account [0] = 15;
		
		status [1] = false;
		names [1] = "风声鹤唳";
		data [1] = 0;
		account [1] = 12;
		
		status [2] = false;
		names [2] = "浪漫满屋";
		data [2] = 0;
		account [2] = 30;
		String name;
		int time;
		boolean exit = false;
		boolean isZero;
		boolean isRight;//借书时间是否正确
		do{
			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("请选择:");
			int choose = input.nextInt();
			switch(choose){
				case 1:
					System.out.println("--->新增DVD");
					for(int i = 0;i<names.length;i++){
						if(names [i] ==null){
							index = i;
							break;
						}
					}
					if(index!=-1){
						System.out.print("请输入DVD名称:");			
						names [index] = input.next();
						System.out.println("新增《"+names[index]+"》成功!");
						}
					break;
				case 2:
					System.out.println("--->查看DVD");
					System.out.println("序号\t状态\t名称\t\t借出日期\t借出次数");
					for(int i = 0;i<names.length;i++){
						if(names [i] ==null){
							index = i;
							break;
						}
					}
					for(int i=0;i<index;i++){
						String x;
						if(status[i] == true){
							x = "已借出";
						}else{
							x = "可借";
						}
						System.out.println((i+1)+"\t"+x+"\t《"+names[i]+"》\t"+data [i]+"日"+"\t"+account [i]+"次");
					}
					break;
				case 3:
					System.out.println("--->删除DVD");
					System.out.print("请输入DVD名称:");
					name = input.next();
					for(int i = 0;i<names.length;i++){
						if(name.equals(names[i])){
							index = i;
							break;
						}
					}
					for(int i=index;i<names.length-1;i++){
						names [i] = names[i+1];
						status [i] = status[i+1];
						data [i] = data[i+1];
						account [i] = account [i+1];
					}
					//names [name.length()-1] = null;
					System.out.println("删除《"+name+"》成功!");
					break;
					
				case 4:
					System.out.println("--->借出DVD");
					System.out.print("请输入DVD的名称:");
					name = input.next();
					for(int i = 0;i<names.length;i++){
						if(names[i].equals(name)){
							index = i;
							break;
						}else{
							index = -1;
						}
					}
					if(index ==-1){
						System.out.println("没有找到匹配信息");
					}else{
						if(status [index] ==true){
							System.out.println("《"+name +"》已被借出!");
						}else{
							status [index] = true;
							do{
								System.out.print("请输入借出日期:");
								time = input.nextInt();
								if(time<1||time>31){
									isRight = false;
								}else{
									isRight = true;
									data [index] =time;
								}
							}while(!isRight);
							account [index]++;
						}
					}
					break;
				case 5:
					boolean isfind5 = false ;
					System.out.println("--->归还DVD");
					System.out.print("请输入DVD名称:");
					name = input.next();
					for(int i = 0;i<names.length;i++){
						if(names [i] ==null){
							index = i;
							break;
						}
					}
					for(int i = 0;i<=index;i++){
						if(name.equals(names [i])){
							if(status [i]==true){
								do{
									System.out.println("请输入归还日期:");
									time = input.nextInt();
									if(time<31||time>data [i]){
										System.out.println("归还《"+name+"》成功!");
										System.out.println("借出日期是:"+data [i]);
										System.out.println("归还日期是:"+time);
										System.out.println("应付租金(元):"+(time - data[i]));
										isRight = true;	
									}else{
										isRight = false;
										System.out.println("归还日期不能小于借出日期;一个月只有31天!");
									}
								}while(!isRight);
								isfind5 = true;
								break;
							}else{
								System.out.println("该DVD没有被借出!无法进行归还操作!");
								isfind5 = true;
								break;
							}
						}else{
							isfind5 = false;
						}
					}
					if(!isfind5){
						System.out.println("没有找到匹配的信息!");
						break;
					}
					break;
				case 6:
					System.out.println("退出DVD...");
					exit =true;
					return;
				default :
					System.out.println("输入错误,请重新输入");
				}
			
			System.out.println("**************************");
			
			do{
				System.out.print("输入0返回:");
				if(0!= input.nextInt()){
					isZero = false;
				}else{
					isZero = true;
				}
			}while(!isZero);
			
				
		}while(!exit);
	}
}



0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:12055次
    • 积分:304
    • 等级:
    • 排名:千里之外
    • 原创:15篇
    • 转载:15篇
    • 译文:1篇
    • 评论:0条