无法打印出我的阵列

时间:2016-05-26 03:46:18

标签: java arrays system.out

public class LibraryMenu {

static Scanner input = new Scanner(System.in);
static Holding[]holding = new Holding[15];
static Member[]member = new Member[15];
static int hold = 0;
private static Scanner scanner;
public static void main(String[] args){
    int options;
    do{
        scanner = new Scanner(System.in);

        System.out.println();
        System.out.println("Library Management System");

        System.out.println("1. Add Holding");
        System.out.println("2. Print All Holding");

        options = scanner.nextInt();
        switch(options){

        case 1:
            addHolding();
            break;
        case 2:
            print();
            break;
        default:
            System.out.println("Please");
        }

    }while(options != 3);
    System.out.println("I'm out");

}
public static void addHolding(){
    int options1;
    do{
    System.out.println();
    System.out.println("1. Book");
    System.out.println("2. Video");
    System.out.println("3. Return");

    options1 = input.nextInt();

    switch(options1){

    case 1:
        addBook();
        break;

    case 2:
        addVideo();
        break;

    default:
        System.out.println("Please enter the following options");

    }

    }while(options1 != 3);

}

public static void addBook(){

    System.out.println("Title: " + "\t");
    String title = input.next();
    System.out.println("ID: " + "\t");
    String holdingId = input.next();   
    Book tempbook = new Book(title, holdingId);
    holding[hold] = tempbook;
    ++hold;


}

public static void addVideo(){
    System.out.println("Title: ");
    String title = input.next();
    System.out.println("ID: ");
    String holdingId = input.next();
    System.out.println("Loan Fee: ");
    int loanFee = input.nextInt();
    Video tempvideo = new Video(holdingId, title, loanFee);
    holding[hold] = tempvideo;
    ++hold;

}

public static void print(){

    for(int i = 0; i < holding.length; i++){
        System.out.println(holding[i]);


    }

}
}

当我使用print()方法时,没有任何显示。想知道代码有什么问题,以及为什么不打印出来。使用用户输入来添加书籍和视频等。试图在互联网上查找此问题,但似乎无法找到它。

0 个答案:

没有答案