A class called Book is designed (as shown in the class diagram) to model a book written by one author. It contains: Four private instance variables: name (String), price (double) static, and qty (int); Two constructors: public Book (String name, double price) { ...... } public Book (String name, double price, int qty) { ...... } getters/setters methods getName(), getPrice(), setPrice(), getQty(), setQty(). A toString() that returns book values. A class called Author is designed to model a book's author. It contains: Four private instance variables: name (String), email (String), and gender (char of either 'm' or 'f') and arrayList of Books. One constructor to initialize the name, email and gender with the given values; public Author (String name, String email, char gender) {......} public getters/setters. A toString() method that returns author object. A method addBook(Book b) which will add book in the Arraylist of books. A removeBook(String name) method which remove particular book form the list. Also write a test driver called to test all the public methods in the class Auth
OOPs
In today's technology-driven world, computer programming skills are in high demand. The object-oriented programming (OOP) approach is very much useful while designing and maintaining software programs. Object-oriented programming (OOP) is a basic programming paradigm that almost every developer has used at some stage in their career.
Constructor
The easiest way to think of a constructor in object-oriented programming (OOP) languages is:
A class called Book is designed (as shown in the class diagram) to model a book written by one author. It contains:
- Four private instance variables: name (String), price (double) static, and qty (int);
- Two constructors:
- public Book (String name, double price) { ...... }
- public Book (String name, double price, int qty) { ...... }
- getters/setters methods getName(), getPrice(), setPrice(), getQty(), setQty().
- A toString() that returns book values.
A class called Author is designed to model a book's author. It contains:
- Four private instance variables: name (String), email (String), and gender (char of either 'm' or 'f') and arrayList of Books.
- One constructor to initialize the name, email and gender with the given values;
public Author (String name, String email, char gender) {......}
- public getters/setters.
A toString() method that returns author object. - A method addBook(Book b) which will add book in the Arraylist of books.
- A removeBook(String name) method which remove particular book form the list.
Also write a test driver called to test all the public methods in the class Author.
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 2 images