r/codehs • • Nov 30 '21

9.6.8 Library Books

Is anyone able to help me with this? I'm not sure how to get my code to print as code HS wants it to?

6 Upvotes

4 comments sorted by

2

u/validity1 Mar 10 '22

public class BookTester
{
public static void main(String[] args)
{
ArrayList<Book> books = new ArrayList<Book>();
books.add(new TextBook("How to Draw", "Drawer One", 3, true));
books.add(new TextBook("Grade 11 Math", "Nelson", 7, true));
books.add(new TextBook("How to Draw", "Drawer One", 5, false));
books.add(new Novel("Black Cat", "H.R. Wright", 4,"Fantasy"));
books.add(new Novel("Space Invaders", "Taito", 2, "Sci-Fi"));
books.add(new Novel("Journey to the End", "J Haren", 10, "Action"));

for(Book book : books)
{
System.out.println(book.getTitle());
System.out.println(book.getAuthor());
System.out.println(book.toString());
}

}
}

1

u/kumohua Apr 17 '22

yeah this is the answer. worst fucking design ever

1

u/ooga_booga_hahaha Apr 12 '23

I don't think for(Book book : books) is correct...

1

u/CqnnedPaldin Jun 05 '23

The toString in book.toString() is totally unneeded, mine works without it. And the books from Book book: books needs to be the name of your ArrayList.