Click here to Skip to main content
15,891,828 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How can I print this:
AudioBook book = new AudioBook ("Harry Potter", "Joan Rowling",LiteratureGenre.Romance, Locale.CANADA,LocalDate.of(2000, 7, 8),
                               "Someone name",LocalTime.of(1, 25), 0);



It prints everything, but not this part
"Harry Potter", "Joan Rowling",LiteratureGenre.Romance, Locale.CANADA,LocalDate.of(2000, 7, 8)


This is the constructor and toString method:

public AudioBook(String bookName, String bookAuthor, LiteratureGenre bookGenre, Locale bookLanguage, LocalDate bookDateOfMade,String readerName, LocalTime recordDuration, int priceForDownload) {
		super(bookName,bookAuthor,bookGenre, bookLanguage,bookDateOfMade);
		this.readerName = readerName;
		this.recordDuration = recordDuration;
		this.priceForDownload = priceForDownload;
	}



@Override
	public String toString() {
		return "\nThis Audio book belongs to: " + readerName + " \nThe duration of the book is: " 
					+ recordDuration + " and it's cost: " + priceForDownload + "$";
	}


What I have tried:

List<Book> books = new ArrayList<>();

        AudioBook book = new AudioBook ("Harry Potter", "Joan Rowling",LiteratureGenre.Romance, Locale.CANADA,LocalDate.of(2000, 7, 8),
        						"Someone name",LocalTime.of(1, 25), 0);
        
        
        AudioBook book1 = new AudioBook ("Book Name", "Author",LiteratureGenre.Poetry, Locale.UK,LocalDate.of(1965, 12, 5),
				"Reader name",LocalTime.of(1, 10), 7);
        
        
        Book b1 = new Book("Alisa in Wonderland","Anybody",LiteratureGenre.Fiction, Locale.GERMAN, LocalDate.of(2019, 1, 1));
      
       
        Book b2 = new Book("Dune", "Author",LiteratureGenre.History,Locale.ITALIAN, LocalDate.of(2020, 4, 1));

        books.add(b1);
        books.add(b2);
        books.add(book1);
        books.add(book);

        System.out.println("<Books>:");
        for (Book b : books) {
            System.out.println(b);
        }
Posted
Updated 13-Dec-21 1:57am
Comments
Richard MacCutchan 13-Dec-21 8:09am    
Your toString method only lists three properties. You need to correct it to include the properties from the parent class.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900