Reference no: EM132076103
Need help on JAVA homework.
The class below describes a Book. In the next questions, you will write a class called Dictionary.
For full credit, follow good principles of class design, encapsulation, and inheritance.
Recommend writing the class in your development environment to make sure it compiles and then copying the code into the appropriate question
public class Book {
private String title, author;
private int copyrightYear;
public Book(String title, String author, int copyrightYear) {
this.title = title;
this.author = author;
this.copyrightYear = copyrightYear;
}
public String getTitle() {
return title;
}
public String getAuthor() {
return author;
}
public int getCopyrightYear() {
return copyrightYear;
}
public void setAuthor(String author) {
this.author = author;
}
public void setTitle(String title) {
this.title = title;
}
public void setCopyrightYear(int copyrightYear) {
if(copyrightYear > 0) {
this.copyrightYear = copyrightYear;
}
}
@Override
public String toString() {
return title + " by " + author + " (" + copyrightYear + ")";
}
}
Question 1
Write the class header and the instance data variables for the Dictionary class.
A dictionary is a book that is further described by the number of words in the dictionary.
Question 2
Write a constructor for the Dictionary class. The constructor should initialize the instance data variables using parameters. The parameters should specify all information needed to describe a dictionary.
Question 3
Write accessor and mutator (getter and setter) methods. Include validity checking where appropriate.
Question 4
Write a toString method to return a text representation of the book. The text representation should include the title, author, year, and number of words, like this:
The Dictionary by Merriam-Webster (2015)
contains 171,500 words
Question 5
Write the equals method (including the method header) for the Book class (not the dictionary class). Two book objects are logically equivalent if they have the same title, author, and copyright year.
Question 6
Write code that would go inside of a main method. The code should create one book object and one dictionary object and invoke at least two methods on each object. Also include a statement to print a text representation of the book and the dictionary to the console.