Nội dung text Object methods_Book Author Actvity.pdf
The design class diagram below shows the class called Author, which models an author of a book. A class called Book, which models a book written by ONE author and composes an instance of Author as its instance variable, is also shown. Write the Author and Book classes. The class Author contains: ➔ Two private instance variables: name (String) and email (String) ➔ A constructor to initialize the name and email ➔ A public getters and setters: getName, getEmail, setName, setEmail ➔ A toString() method that returns author’s name and email Author -name: String -email: String +Author(name: String, email: String) +getName(): String +getEmail(): String +setEmail(email: String): void +toString(): String The class Book contains: ➔ A constructor to initialize the isbn, title, author, price and quantity ➔ A public method getIsbn, getTitle, getAuthor, getPrice and setPrice, getQty and setQty ➔ A toString() method that returns isbn, title, author (associated to author class), price and quantity Book -isbn: String -title: String -author: Author -price: double -qty: int=0 +Book (isbn: String, title: String, author: Author, price: double, qty: int) +getIsbn(): String +getTitle(): String +getAuthor(): Author +getPrice(): double +setPrice(price: double): void +getQty(): int +setQty(qty: int): void +toString(): String Use BookTest class as your test driver and refer to the sample output below. ** Please set a new email and new price and quantity in the main method, then display it as the second output ➔ Five private instance variables: isbn (String), name (String), author (a class author that you will be created that has one and only one author and associated to authors name and email), price (double) and qty (int with zero initial value)