我无法在某些扫描仪上输入任何内容

时间:2015-11-29 08:06:52

标签: java

过去几天我一直在创建一个简单的图书馆系统,由于这个网站,我已经完成了每个架子,显示等的人口。目前,我遇到了借款人借用实体书,下载电子书或借用设备的问题。首先,运行时出现零点异常错误,调用borrowBookPH时出错,最后,我不知道该书是否真正被借用或下载。

我发布了一个缩短的图书馆计划代码。

编辑:我已经设法弄清楚是什么导致了我的问题。现在我的问题是当我被问到“输入书/设备名称:”时,我无法输入任何字符串。我的代码上没有错误/警告。

驱动程序类:

System.out.println("Input Borrower: ");
    int borrowerID = sc.nextInt();

    switch(borrowerID){

    case 11074450: System.out.println("1. Physical 2. Digital 3. Equipment: ");
                    int choice = sc.nextInt();
                    switch(choice){
                        case 1: System.out.println("Input Book Name: ");
                                String borrowIP = sc.nextLine();
                                for(int i = 0; i < ph.size(); i++){
                                    if(borrowIP.equals(ph.get(i).getTitle()))
                                        brw1.borrowBookPH(ph.get(i));
                                }
                                break;
                        case 2: System.out.println("Input Book Name: ");
                                String borrowID = sc.nextLine();
                                for(int i = 0; i < dg.size(); i++){
                                    if(borrowID.equals(dg.get(i).getTitle()))
                                        brw1.downloadBookDG(dg.get(i));
                                }
                                break;
                        case 3: System.out.println("Input Equipment Name: ");
                                String borrowIE = sc.nextLine();
                                for(int i = 0; i < eqp.size(); i++){
                                    if(borrowIE.equals(eqp.get(i).getName()))
                                        brw1.borrowEQ(eqp.get(i));
                                }
                                break;
                    }
                    break;
    case 10355230: System.out.println("1. Physical 2. Digital 3. Equipment: ");
                    int choice2 = sc.nextInt();
                    switch(choice2){
                        case 1: System.out.println("Input Book Name: ");
                                String borrowIP = sc.nextLine();
                                for(int i = 0; i < ph.size(); i++){
                                    if(borrowIP.equals(ph.get(i).getTitle()))
                                        brw2.borrowBookPH(ph.get(i));
                                    }
                                break;
                        case 2: System.out.println("Input Book Name: ");
                                String borrowID = sc.nextLine();
                                for(int i = 0; i < dg.size(); i++){
                                    if(borrowID.equals(dg.get(i).getTitle()))
                                        brw2.downloadBookDG(dg.get(i));
                                    }
                                break;
                        case 3: System.out.println("Input Equipment Name: ");
                                String borrowIE = sc.nextLine();
                                for(int i = 0; i < eqp.size(); i++){
                                    if(borrowIE.equals(eqp.get(i).getName()))
                                        brw2.borrowEQ(eqp.get(i));
                                }
                                break;
                    }
                    break;
    case 11423970: System.out.println("1. Physical 2. Digital 3. Equipment: ");
                    int choice3 = sc.nextInt();
                    switch(choice3){
                        case 1: System.out.println("Input Book Name: ");
                                String borrowIP = sc.nextLine();
                                for(int i = 0; i < ph.size(); i++){
                                    if(borrowIP.equals(ph.get(i).getTitle()))
                                        brw3.borrowBookPH(ph.get(i));
                                }
                                break;
                        case 2: System.out.println("Input Book Name: ");
                                String borrowID = sc.nextLine();
                                for(int i = 0; i < dg.size(); i++){
                                    if(borrowID.equals(dg.get(i).getTitle()))
                                        brw3.downloadBookDG(dg.get(i));
                                }
                                break;
                        case 3: System.out.println("Input Equipment Name: ");
                                String borrowIE = sc.nextLine();
                                for(int i = 0; i < eqp.size(); i++){
                                    if(borrowIE.equals(eqp.get(i).getName()))
                                        brw3.borrowEQ(eqp.get(i));
                                }
                                break;
                    }
                    break;
    case 11092001: System.out.println("1. Physical 2. Digital 3. Equipment: ");
                    int choice4 = sc.nextInt();
                    switch(choice4){
                        case 1: System.out.println("Input Book Name: ");
                                String borrowIP = sc.nextLine();
                                for(int i = 0; i < ph.size(); i++){
                                    if(borrowIP.equals(ph.get(i).getTitle()))
                                        brw4.borrowBookPH(ph.get(i));
                                }
                                break;
                        case 2: System.out.println("Input Book Name: ");
                                String borrowID = sc.nextLine();
                                for(int i = 0; i < dg.size(); i++){
                                    if(borrowID.equals(dg.get(i).getTitle()))
                                        brw4.downloadBookDG(dg.get(i));
                                }
                                break;
                        case 3: System.out.println("Input Equipment Name: ");
                                String borrowIE = sc.nextLine();
                                for(int i = 0; i < eqp.size(); i++){
                                    if(borrowIE.equals(eqp.get(i).getName()))
                                        brw4.borrowEQ(eqp.get(i));
                                }
                                break;
                    }
                    break;
    case 10911550: System.out.println("1. Physical 2. Digital 3. Equipment: ");
                    int choice5 = sc.nextInt();
                    switch(choice5){
                        case 1: System.out.println("Input Book Name: ");
                                String borrowIP = sc.nextLine();
                                for(int i = 0; i < ph.size(); i++){
                                    if(borrowIP.equals(ph.get(i).getTitle()))
                                        brw5.borrowBookPH(ph.get(i));
                                }
                                break;
                        case 2: System.out.println("Input Book Name: ");
                                String borrowID = sc.nextLine();
                                for(int i = 0; i < dg.size(); i++){
                                    if(borrowID.equals(dg.get(i).getTitle()))
                                        brw5.downloadBookDG(dg.get(i));
                                }
                                break;
                        case 3: System.out.println("Input Equipment Name: ");
                                String borrowIE = sc.nextLine();
                                for(int i = 0; i < eqp.size(); i++){
                                    if(borrowIE.equals(eqp.get(i).getName()))
                                        brw5.borrowEQ(eqp.get(i));
                                }
                                break;
                    }
                    break;
    }

借款人类:

private Physical borrowedP;
private Digital borrowedD;
private Equipment borrowedE;

public void borrowBookPH(Physical borrow){

    this.borrowedP = borrow;
    this.borrowedP.borrowPH(this);

public void downloadBookDG(Digital borrow){

    this.borrowedD = borrow;
    this.borrowedD.borrowDG(this);
    this.borrowedD.countDownload();

}

public void borrowEQ(Equipment borrow){

    this.borrowedE = borrow;
    this.borrowedE.borrowEQ(this);

}

物理等级:

    public void borrowPH(Borrower borrower){

    this.isAvailable = false;
    this.borrower = borrower;

}

public void returnPH(){

    this.isAvailable = true;
    this.borrower = null;

}

数字课程:

    public void countDownload(){

    this.count += 1;

}

public void showDownload(){

    System.out.println(this.count);
}

public void borrowDG(Borrower borrower){

    this.status = false;
    this.borrower = borrower;
    countDownload();

}

设备类:

    public void borrowEQ(Borrower borrower){

    this.isAvailable = false;
    this.borrower = borrower;

}

乎乎。请帮忙。这个'我不能打字'令人沮丧。

1 个答案:

答案 0 :(得分:0)

至于错误,你的代码似乎缺少一些try {} catche(){}和测试(物理借用,还是我可以把它交给某人?)。你的代码也缺少了inicialization部分,这也可能有问题。

对于方法中的错误,请尝试跟踪它,或者使用相应的代码发布e.printStackTrace()。

借用或下载不应该是一个问题,你将它们放在不同的类中并且命名不同,那么你究竟是什么意思“我不知道这本书是真的被借用还是下载了”