Question: Here comes assignment 2 // Book class public class Book { private String title; private String ISBN; //Book constructor public Book(String title, String iSBN) {

 Here comes assignment 2 // Book class public class Book {private String title; private String ISBN; //Book constructor public Book(String title, String

Here comes assignment 2

// Book class

public class Book {

private String title;

private String ISBN;

//Book constructor

public Book(String title, String iSBN) {

this.title = title;

this.ISBN = iSBN;

}

public String toString() {

return "Book [title=" + title + ", ISBN=" + ISBN + "]";

}

public String getTitle() {

return title;

}

public void setTitle(String title) {

this.title = title;

}

public String getISBN() {

return ISBN;

}

public void setISBN(String iSBN) {

ISBN = iSBN;

}

}

public class TextBook extends Book {

//TextBook Constructor.

public TextBook(String title, String iSBN,String course) {

super(title, iSBN);

// TODO Auto-generated constructor stub

this.course=course;

}

private String course;

public String getCourse() {

return course;

}

public void setCourse(String course) {

this.course = course;

}

public String toString() {

return "TextBook [course=" + course + ", toString()=" + super.toString() + "]";

}

}

public class Novel extends Book {

private String genre;

//Novel constructor

public Novel(String title, String iSBN,String genre) {

super(title, iSBN);

this.genre=genre;

}

public String getGenre() {

return genre;

}

public void setGenre(String genre) {

this.genre = genre;

}

public String toString() {

return "Novel [genre=" + genre + ", toString()=" + super.toString() + "]";

}

}

//Program driver

public class Main {

public static void main(String[] args) {

Book book = new Book("Java Introduction","ISBN1234");

//Testing book set/get methods

System.out.println("Testing book methods");

System.out.println(book.getTitle());

System.out.println(book.getISBN());

book.setISBN("ISBN123XXX");

System.out.println("Changed ISBN"+book.getISBN());

System.out.println();

System.out.println();

TextBook textBook = new TextBook("DataStructures in C","ISBN1235","Course DS100 DataStructures");

System.out.println("Testing textBook methods");

System.out.println(textBook.getTitle());

System.out.println(textBook.getISBN());

System.out.println(textBook.getCourse());

textBook.setCourse("Course DS105 in Java");

System.out.println("Changed Course"+textBook.getCourse());

System.out.println();

System.out.println();

Novel novelBook = new Novel("Sherlock Holmes Novel","ISBN1236","Fiction");

System.out.println("Testing novelBook methods");

System.out.println(novelBook.getTitle());

System.out.println(novelBook.getISBN());

System.out.println(novelBook.getGenre());

System.out.println();

System.out.println();

//Testing toString methods of the objects

System.out.println(book.toString());

System.out.println(textBook.toString());

System.out.println(novelBook.toString());

}

}

Seminar Activities Building on assignment 2 we'll add to the class hierarchy and add equals methods to the classes. Problem Given the class hierarchy from assignment 2 we'll add an Item class that will represent an item in a store. An item has a price (double) and a UPC code (long int) but does not exist on its own, it only exists to support sub classing (so it's an abstract class). The Book class from assignment 2 needs to be modified to extend from the Item class. Additionally the store sells pens so we'll need a Pen class with a colour attribute in it. Secondly implement equals methods in all of the classes as well, and like assignment 2 test all of the functionality. (use the parent's equals method and add to it in the child). Use the code below as a starting point, and modify it for the class you are using it in. Notes: Child classes should call parent methods whenever possible to minimize code duplication. The driver program must test all the methods in each of the classes. Include comments in your output to describe what you are testing, for example System.out.println("testing Book toString. accessor and mutator. Print out some blank lines in the output to make it easier to read and understand what is being output. Assignment Submission: Submit a print-out of each class file, the driver file and a sample of the output. Include a UML diagram also. (There's an inheritance arrow below you can use) Marking Checklist 1. Does EACH class have all the usual methods? 2. Are all methods in EACH class tested, including child objects calling inherited parent methods? 3. Does the child class call the parent's constructor? 4. Does the child class override the parent's toString? 5. Does the child class override the parent's equals? 6. Does the output produced have lots of comments explaining what is being output? 7. Does each class, and the output, have blank lines and appropriate indenting to make them more readable? Here's an overridden equals method, in a Person class: public boolean equals(Object 0) { if (this == 0) // self check return true; if(o=null)__// null check return false; if (!(o instanceof Person) // type check and cast return false; Person person = (Person) o; return this.firstName.equals(Rerson firstName) && this.lastName.equals(person.lastName)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!