Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(JAVA QUESTION) Create 4 classes Author, Book, Library, Driver Attach the .java for the 4 above programs. Follow the steps carefully. Create a class called

(JAVA QUESTION)

Create 4 classes

Author, Book, Library, Driver

Attach the .java for the 4 above programs.

Follow the steps carefully.

Create a class called Author.java.(Need to import the Scanner and setup)

This class has 2 instance variables

private String fName

private String lName

Create 3 constructors

One constructor has no parameters. Inside the constructor prompt the user to enter the first and last name and store them in the instance variables.

One constructor has 2 Strings as parameters public Author(String fn, String ln)

One is a copy constructor

Create setters and getters for each instance variables-(require total 4 methods) public String getFName() - example header for getters public void setFName(String fn) - example header for setter

Create a toString method public String toString()

Output should look like:

Author is Jack Frost

Create an equals method - if the first and last name are the same return true, otherwise false public boolean equals (Author other)

2. Create a class called Driver.

Create three Author objects using the three constructor. Use setters and getters, toString and equals

3. Create a class called Book.java. a. It has 3 instance variables( Need to import Scanner and setup)

i. private String title;

ii. private String ISBN;

iii. private Author auth;

b. Create 3 constructors for Book. One has 3 parameters

public Book (String t, String I, Author a){

The second constructor has no parameters- prompt the user to enter the fields

public Book (){

The third is a copy constructor

public Book( Book other)

c. Create a setters/getters for each instance variable.(6 total methods)

d. Create a toString for Book(make sure uses toString from Author)

public String toString(){

Output should be:

Title is MobyDick

ISBN is 123456787

Author is Jack Frost

e. Write an equals method for Book. Follow the example for Author. To test to see if the two books are the same - compare just the ISBN.

4. Modify the Driver to now create 3 Book objects( use each constructor) and test.

Note - the Author object a1 and a2 has to be created before you can use it in Book

Book b1 = new Book(Poems , ISBN12345, a1);

Test the methods you added in Book(setters/getters/toString/equals)

5. Create a class called Library

Library has two instance variables

String name

ii. private Book[ ] lib = new Book[3]; // array of Books

b. Library has one constructor - no argument. Prompt the user for title and use the no argument in Book

c. . Write a toString for Library

public String toString(){

6. . Modify Driver to include creating a Library

Library lib = new Library();

Print out the information- uses toString

c. Run the driver . Copy the output from the terminal window to the Driver program as a comment at the bottom. Go back and make sure you proved in the Driver that each piece of the code worked. Bothe the true and false part of the equals, all setters/getters etc.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions