程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> arraylist-我怎麼才能在main裡輸出下面的bkdata,謝謝各位大神

arraylist-我怎麼才能在main裡輸出下面的bkdata,謝謝各位大神

編輯:編程綜合問答
我怎麼才能在main裡輸出下面的bkdata,謝謝各位大神

public class BookData {
private static ArrayList book = new ArrayList();
private static ArrayList customer = new ArrayList();

public static ArrayList<Customer> getCustomer() {
    return customer;
}

public static void setCustomer(ArrayList<Customer> customer) {
    BookData.customer = customer;
}

public static ArrayList<Book> getBook() {
    return book;
}

public static void setBook(ArrayList<Book> book) {
    BookData.book = book;
}

public static void bkdata(){                            //創建書籍種類和會員信息
    BookDaoImp bookDaoImp = new BookDaoImp();
    bookDaoImp.create("計算機類", 300) ;
    bookDaoImp.create("文史類", 300);
    bookDaoImp.create("小說類", 300);
    CustomerDaoImp customerDaoImp = new CustomerDaoImp();
    customerDaoImp.create("張三","vip會員");
    customerDaoImp.create("李四","會員");
    customerDaoImp.create("王五","普通");
}

}

最佳回答:


import java.util.ArrayList;
import java.util.List;

/**

  • Created by prd on 2015/8/4. */

public class BookData {
private static ArrayList book = new ArrayList();
private static ArrayList customer = new ArrayList();
private static List bookdaoimp = new ArrayList();
// public static ArrayList getCustomer() {
// return customer;
// }
//
// public static void setCustomer(ArrayList customer) {
// BookData.customer = customer;
// }
//
// public static ArrayList getBook() {
// return book;
// }
//
// public static void setBook(ArrayList book) {
// BookData.book = book;
// }

public static void bkdata() {                            //創建書籍種類和會員信息

    BookDaoImp bookDaoImp = new BookDaoImp();
    bookDaoImp.create("計算機類", 300);
    bookdaoimp.add(bookDaoImp);
    BookDaoImp bookDaoImp1 = new BookDaoImp();
    bookDaoImp1.create("文史類", 300);
    bookdaoimp.add(bookDaoImp1);
    BookDaoImp bookDaoImp2 = new BookDaoImp();
    bookDaoImp2.create("小說類", 300);
    bookdaoimp.add(bookDaoImp2);

    //輸出.
    for (BookDaoImp bk : bookdaoimp) {

        System.out.println("name->" + bk.getName() + ",total->" + bk.getTotal());
    }

// CustomerDaoImp customerDaoImp = new CustomerDaoImp();
// customerDaoImp.create("張三","vip會員");
// customerDaoImp.create("李四","會員");
// customerDaoImp.create("王五","普通");
}

public static void main(String[] args) {
    bkdata();
}

}

class BookDaoImp {

private String name;
private int total;

public void create(String name, int total) {
    setName(name);
    setTotal(total);
}


public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

public int getTotal() {
    return total;
}

public void setTotal(int total) {
    this.total = total;
}

}


你的代碼不全,大致就是這樣輸出的。

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved