package books;
import java.io.PrintStream;
public class Book {
private String title;
private String author;
private String isbn;
public Book(String title, String author, String isbn) {
this.title = title;
this.author = author;
this.isbn = isbn;
}
public String getTitle() {
return title;
}
public String getAuthor() {
return author;
}
public String getIsbn() {
return isbn;
}
public void writeAsXml(PrintStream ps) {
ps.println(" ");
ps.println(" " + title + "");
ps.println(" " + author + "");
ps.println(" " + isbn + "");
ps.println(" ");
}
}
package books;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.List;
public class BookList {
private List books = new ArrayList();
public BookList() {
// empty
}
public void addBook(Book book) {
books.add(book);
}
public void writeAsXml(PrintStream ps) {
ps.println("");
for (Book b : books) {
b.writeAsXml(ps);
}
ps.println("");
ps.close();
}
public void add(Book b) {
books.add(b);
}
}
package test;
import books.Book;
import books.BookList;
public class BooksTest {
/**
* BookListクラスのテストプログラム
*/
public static void main(String[] args) {
BookList bl = new BookList();
Book b1 = new Book("Java入門", "鈴木 健", "1234-5678-90");
bl.add(b1);
Book b2 = new Book("コンピュータ入門", "佐藤 桂子", "1234-8765-43");
bl.add(b2);
Book b3 = new Book("OS入門", "田中 和博", "1234-1234-56");
bl.add(b3);
bl.writeAsXml(System.out);
}
}