| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 513 人关注过本帖
标题:求各位大神用一个数组帮我完善下下! 有很多BUG
只看楼主 加入收藏
liuxinghuao
Rank: 2
等 级:论坛游民
帖 子:6
专家分:20
注 册:2012-8-4
收藏
 问题点数:0 回复次数:1 
求各位大神用一个数组帮我完善下下! 有很多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 编辑 ]
搜索更多相关主题的帖子: public package void dvd 
2012-08-11 18:54
liuxinghuao
Rank: 2
等 级:论坛游民
帖 子:6
专家分:20
注 册:2012-8-4
收藏
得分:0 
是不是太小儿科了,对于初学者还是有点难度的,好像每个方法融不到一起
2012-08-11 21:06
快速回复:求各位大神用一个数组帮我完善下下! 有很多BUG
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.037427 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved