Skills to be Applied

In addition to what has been covered in previous assignments, the use of the following items, discussed in class, will probably be needed:

Classes
Instance Objects

Accessors/Mutators(Modifiers) methods
Visibility Modifiers (Access specifier) - public, private, etc. Encapsulation concept
Aggregation relationship between classes

Program Description

Class Diagram: see image.

Assignment #4 will be the construction of 2 new classes and a driver program (the class containing a main method).

Publication class

The Publication class describes the publication information of a book. It has following attributes:

Attribute name, Attribute type, Description
ISBN, String, The ISBN of book
version, int, The version of book
price, double, The price of book

The following constructor should be provided to initialize each attribute. This constructor initializes the value of ISBN to "?", version to 1 and price to 0.0

public Publication( )

The following accessor methods should be provided to get the attributes:
public String getISBN()
public int getVersion()
public double getPrice()

The following modifier(mutator) methods should be provided to set the attributes:
public void setISBN(String newISBN)
public void setVersion(int newVersion)
public void setPrice(double newPrice)

The following method must be defined: public String toString()

toString method should return a string of the following format:

Edition: 2
ISBN: 978-0471791911 Price: $89.95

where 2 is the version/edition number, "978-0471791911" is ISBN, and 89.95 is price. So you need to insert Strings such as Edition: ISBN: and Price:.

Attribute name, Attribute type, Description
title, String, The title of the book
author, String, The author of the book
pub, Publication, The publication info of the book

The following constructor should be provided to initialize each attribute. This constructor initializes the value of title and author to "?" and the value of ISBN, version, and price to ?, 1 and 0.0 (respectively) by instantiating an object of Publication using the constructor of the Publication class.

public Book( )

The following accessor methods should be provided to get the attributes:
public String getTitle()
public String getAuthor()
public Publication getPublication()

The following modifier(mutator) methods should be provided to change the attributes:
public void setTitle(String newTitle)
public void setAuthor(String newAuthor
public void setPublication(int newVersion, String newISBN, double newPrice)

The following method must be defined: public String toString()

The toString() method constructs a string of the following format:

nTitle:tJava for Everyonen Author:tCay S. Horstmannn Edition:2n ISBN:t978-0471791911n Price:t$89.95nn

Assignment4

(Note that this part is already done in the Assignment4.java file that is given to you. This explains each functionality of this class.)

In this assignment, download Assignment4.java file, save and use it for your assignment. You do not need to modify Assignment4.java file. You only need to write Book.java and Publication.java files.

The following is the description of Assignment4 class.

The driver program will allow the user to interact with your other class modules. The purpose of this module is to handle all user input and screen output. The main method should start by displaying the following menu in this exact format:

ChoicettActionn ------tt------n AttAdd Bookn DttDisplay Bookn QttQuitn
?ttDisplay Helpnn

Next, the following prompt should be displayed:

What action would you like to perform?n

Read in the user input and execute the appropriate command. After the execution of each command, re-display the prompt. Commands should be accepted in both lowercase and uppercase.

Add Book

Your program should display the following prompt:

Enter book title:n

Read in the user input and set the title on the book object. Then the following prompt:

Enter book author:n

Read in the user input and set the author on the book object. Then the following prompt:

Enter book version:n
Read in the user input. Then the following prompt: Enter book ISBN:n
Read in the user input. Then the following prompt: Enter book price:n

Read in the user input and set the version, ISBN and price on the book object.

Note that there is only one Book object in this assignment. Thus when "Add Book" option is selected more than once, the new one overwrites the old Book object information.

Display Book

Your program should display the book information in the following format:

nTitle:tJava for Everyonen Author:tCay S. Horstmannn Edition:2n
ISBN:t978-0471791911n Price:t$89.95nn

Make use of the toString method of the Book class to display this information. The toString method is used together with System.out.print method. (System.out is NOT to be used within the toString method.)

Quit

Your program should stop executing and output nothing.

Display Help

Your program should redisplay the "choice action" menu.

Invalid Command

If an invalid command is entered, display the following line:

Unknown actionn

Input

The attached files: input1.txt, input2.txt, input3.txt, input4.txt are the test cases that will be used as input for your program (Right-click and save).

Output

The attached files: output1.txt, output2.txt, output3.txt, output4.txt

are the expected outputs of the corresponding input files from the previous section (Right-click and save).

Error Handling

Your program is expected to be robust to handle all test cases.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.