Books as strings

Report a typo

Here's a class named Book. It has three fields: string field title, int field yearOfPublishing and an array of strings authors. Override the method toString in the class to return string representations of books.

The overridden method must return a string including all field-value pairs separated by commas. An array of authors always includes at least one author. Do not add a comma after the last author.

Here is an example: "title=Java 8 & 9 in Action,yearOfPublishing=2017,authors=[Mario Fusco,Alan Mycroft]". Pay attention, the quote marks are not part of the string.

Write a program in Java 17
class Book {

private String title;
private int yearOfPublishing;
private String[] authors;

public Book(String title, int yearOfPublishing, String[] authors) {
this.title = title;
this.yearOfPublishing = yearOfPublishing;
this.authors = authors;
}
}
___

Create a free account to access the full topic