Question: JAVA For this assignment, you will write a program that simulates a bookstore database. You will need to implement 3 classes Media.java (an abstract class)
JAVA For this assignment, you will write a program that simulates a bookstore database.
You will need to implement 3 classes
Media.java (an abstract class)
Book.java (subclass of Media.java)
TwiceSoldTales.java (bookstore)
Make a new project folder in Eclipse to store the above 3 classes
You will also be working with an input file of data about some books.
Next, place a new textfile named books.txt into your project folder, and copy and paste the below data into this file:
The Time in Between Maria Duenas 9.86 43-453-44 2 Bleak House Charles Dickens 8.99 35-678-97 4 Rebecca Daphe Dumaurier 5.50 32-423-82 5 A Room with a View E.M. Forster 7.50 11-778-89 3 Outlander Diana Galbadon 19.95 54-665-65 7 Jane Eyre Charlotte Bronte 7.90 23-456-74 4 The Hunger Games Suzanne Collins 6.90 42-323-22 10 The Woman in White Wilkie Collins 10.75 32-567-89 2 A Face like Glass Frances Hardinge 15.95 44-554-43 1 Lady Audley's Secret Mary Elizabeth Braddon 5.50 12-121-34 1 Murder on the Orient Express Agatha Christie 2.99 98-375-83 8 Middlemarch George Elliot 12.50 12-567-43 4 Our Souls at Night Kent Haruf 11.99 78-474-89 2 Fangirl Rainbow Rowell 10.79 24-137-25 6 Ramona Blue Julie Murphy 9.99 93-283-11 4 The Rosie Project Graeme Simsion 14.99 82-389-31 5 A is for Alibi Sue Grafton 4.55 34-323-21 3 Still Life Louise Penny 18.99 33-443-22 5 Flight Behavior Barbara Kingsolver 9.98 56-382-34 4
Next, copy and paste the below starter code into your files and implement the methods according to the comments provided.
Media.java:
Please do not add any new methods to this class. Instead, implement the provided methods.
public abstract class Media { private String title; private double price; private int numCopies; /** * Default constructor for the Media * class. Calls the three argument * constructor, passing in "title unknown", * 0.0 and 0 */ public Media() { } /** * Constructor for the Media class * @param title the media title * @param price the sale price * @param numCopies the number of copies * currently in stock */ public Media(String title, double price, int numCopies) { } /** * Returns the title of the media * @return the title */ public String getTitle() {
return "";
} /** * Returns the price of the media * @return the price */ public double getPrice() {
return 0.0;
} /** * Returns the current number of * copies available * @return the number of copies */ public int getNumCopies() {
return 0;
} /** * Returns whether there are more than * 0 copies of the media * @return whether any copies are * available to purchase */ public boolean availableToPurchase() { } /** * Sets the price to be a new price * @param price the price of the media */ public void setPrice(double price) { } /** * Determines how to increase the price * each time a copy gets sold (and media * gets rarer) */ public abstract void updatePrice(); /** * Decrements the number of copies * when a media gets sold */ public void decreaseCopies() { } }
Book.java:
Note, consult the Oracle documentation on DecimalFormat for more information.
Please do not add any new methods to this class. Instead, implement the provided methods.
import java.text.DecimalFormat; public class Book extends Media { private String author; private String isbn; private static int numBooks = 0; /** * Default constructor for Book. * Calls the 2 argument constructor * Sets title default to "title unknown" * Sets author default to "author unknown" */ public Book() { } /** * Two argument constructor for the Book * class. Calls the 5 argument constructor * Sets price to a default of 0.0, * isbn to a default of "0" and numCopies * to a default of 0 * @param title the book's title * @param author the book's author */ public Book(String title, String author) { } /** * Constructor for book. Calls media constructor * @param title the book's title * @param author the book's author * @param price the book's price * @param isbn the book's 7-digit isbn * @param numCopies the current num copies */ public Book(String title, String author, double price, String isbn, int numCopies) { } /** * Returns the first and last names * of the author * @return the author */ public String getAuthor() {
return "";
} /** * Returns the 7 digit ISBN number * @return the ISBN number */ public String getISBN() {
return "";
} /** * Returns the total number of books * @return the value of numBooks */ public static int getNumBooks() {
return 0;
} /** * Increases the price of the book by * $0.25 each time a copy is sold */ public void updatePrice() { } /** * Updates numBooks variable by * a specified amount * @param n the number of books to add */ public static void updateNumBooks(int n) { } /** * Overrides equals for Object using the * formula given in class. For the purposes * of this assignment, we will consider * two books to be equal on the basis of * title and author only * @return whether two books have the same * title and author */ @Override public boolean equals(Object o) {
return false;
} /** * Creates a book String in the following format * Title:
TwiceSoldTales.java:
Please add any additional methods to this class that you find necessary, in addition to implementing those that have been provided.
import java.util.ArrayList; import java.util.Scanner; import java.io.File; import java.io.IOException; public final class TwiceSoldTales { private ArrayList
input.close();
} }
Sample Output:
Welcome to Twice Sold Tales! We currently have 80 books in stock! Looking for a specific book? Enter the book information below: Title: Bleak House Author: Charles Dickens We have Bleak House in stock! Title: Bleak House Author: Charles Dickens Price: $8.99 ISBN #: 35-678-97 Copies: 4 Would you like to purchase it (y/n): y Thank you for your purchase! Updated entry for this book: Title: Bleak House Author: Charles Dickens Price: $9.24 ISBN #: 35-678-97 Copies: 3
Sample Output:
Welcome to Twice Sold Tales! We currently have 80 books in stock! Looking for a specific book? Enter the book information below: Title: Dombey and Son Author: Charles Dickens Sorry! We don't carry that title right now. Goodbye!
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
