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;
/**
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;
}
}
你的代碼不全,大致就是這樣輸出的。