JAVA Programming Assignment

Problem 1: Toy and ToyInventory

Robert wants to get organized with a system to keep track of his toys. Implement two classes to help him: Toy and ToyInventory.

Wait Before you Leave! I have something for you😊
Get your college paper done by experts
Place an order in 3 easy steps. Takes less than 5 mins.
Place an Order

Toy must include the following public methods:

● Toy(String name, String description, boolean destroyed) // Constructor that constructs the Toy object

β—‹ name: name of the toy β—‹ description: description of the toy β—‹ destroyed: whether or not this toy is destroyed

Get Assignment Writing Help

Our experts are ready to complete your assignment, course work. essay, test, dissertation, research paper, quiz

Get Started

● String getName() // returns name ● void setName(String name) // sets the name to the given name ● String getDescription() // returns description ● void setDescription(String description) // sets the description to the given

description ● boolean isDestroyed() // Returns true if the toy is destroyed, false otherwise ● void setDestroyed(boolean destroyed) // sets the destroyed property to the

given value

ToyInventory must include the following public methods:

● ToyInventory() // Constructor that constructs a new ToyInventory object ● void addToy(Toy toy) // adds the given toy if a toy with that name doesn’t

already exist in the inventory ● void removeToy(String name) // removes the toy with the given name if it

exists in the inventory ● String getInventoryReport() // returns a String that lists the name, description,

and DESTROYED or NOT DESTROYED for each toy (see example for formatting)

Example:

Toy lamby = new Toy(“Lamby”, “white fluffy stuffed lamb that I got for Christmas”, false); Toy sharky = new Toy(“Sharky”, “blue shark with its mouth chewed off”, true); Toy socky = new Toy(“Socky”, “my brother’s old sock that I like to carry around in my mouth like a treasure”, true); Toy tennisBall = new Toy(“Tennis Ball”, “standard green tennis ball that I play with outside”, false); ToyInventory inventory = new ToyInventory();

inventory.addToy(lamby); inventory.addToy(sharky); inventory.addToy(socky); inventory.addToy(tennisBall); inventory.removeToy(“Sharky”); inventory.getInventoryReport(); // returns: Lamby white fluffy stuffed lamb that I got for Christmas NOT DESTROYED Socky my brother’s old sock that I like to carry around in my mouth like a treasure DESTROYED Tennis Ball standard green tennis ball that I play with outside NOT DESTROYED

Problem 2: BasicAccount

Given the class BankAccount (​BankAccount.java ), implement a subclass of BankAccount called BasicAccount whose withdraw method charges a penalty of $30 for each withdrawal that results in an overdraft (a negative balance).

Example:

BankAccount account = new BasicAccount(100.00) // creates a BasicAccount with an initial balance of 100.00

account.withdraw(80.00); // no overdraft, so no penalty

account.getBalance(); // returns 20.0

account.withdraw(50.00); // charge $30 penalty for overdraft

account.getBalance(); // returns -60.0

account.withdraw(50.00); // charge $30 penalty for overdraft

account.getBalance(); // returns -140.0

https://canvas.eee.uci.edu/courses/32818/files/12631101/download?wrap=1
https://canvas.eee.uci.edu/courses/32818/files/12631101/download?wrap=1

Problems 3: Library

For this assignment, you are given an abstract class LibraryItem (​LibraryItem.java ). You must complete the following:

1. Add an ​equals​ method to LibraryItem 2. Implement three direct subclasses of LibraryItem: DVD (a concrete class),

Magazine (a concrete class), and Book (an abstract class). 3. Implement three concrete subclasses of Book: DigitalBook, PrintBook, and

Audiobook.

Each item type has a loan period and a maximum number of checkouts per item (i.e., a physical item like a print book can only be checked out by one person at a time, whereas a digital item like an audio book can be checked out by multiple people at a time, depending on the number of licenses the library has for that item). This information is given in the below table:

● LibraryItem public method to add: β—‹ boolean equals(Object otherObject) // returns true if otherObject

has the same instance variable(s) value(s) as this LibraryItem ● DVD public methods:

β—‹ DVD(String title, ArrayList actors) // Constructs a DVD object with the given title and actors

β—‹ ArrayList getActors() β—‹ void setActors(ArrayList actors) β—‹ String checkOut() // if this item is not already checked out, this

method checks this item out and returns the loan period; if it is already checked out, returns the String “NOT ALLOWED”; overrides LibraryItem.checkOut()

β—‹ boolean equals(Object otherObject) // returns true if otherObject has the same instance variable(s) value(s) as this DVD

● Magazine public methods:

Item Type Loan Period Max # checkouts per item

DVD 7 days 1

Magazine 7 days 1

Digital Book 14 days 3

Print Book 21 days 1

Audio Book 28 days 2

https://canvas.eee.uci.edu/courses/32818/files/12664693/download?wrap=1
https://canvas.eee.uci.edu/courses/32818/files/12664693/download?wrap=1

β—‹ Magazine(String title, int issueNumber, String publicationDate) // Constructs a Magazine object with the given title, issue number, and publication date

β—‹ int getIssueNumber() β—‹ void setIssueNumber(int issueNumber) β—‹ String getPublicationDate() β—‹ void setPublicationDate(String publicationDate) β—‹ String checkOut() // if this item is not already checked out, this

method checks this item out and returns the loan period; if it is already checked out, returns the String “NOT ALLOWED”; overrides LibraryItem.checkOut()

β—‹ boolean equals(Object otherObject) // returns true if otherObject has the same instance variable(s) value(s) as this Magazine

● Book (abstract class) public methods: β—‹ Book(String title, String author) // Constructs a Book object with the

given title and author β—‹ String getAuthor() β—‹ void setAuthor(String author) β—‹ boolean equals(Object otherObject) // returns true if otherObject

has the same instance variable(s) value(s) as this Book ● DigitalBook public methods:

β—‹ DigitalBook(String title, String author, int numPages) // Constructs a DigitalBook object with the given title, author, and number of pages

β—‹ int getNumPages() β—‹ void setNumPages(int numPages) β—‹ String checkOut() // if the max number of checkouts for this item

has not already been reached, this method checks this item out and returns the loan period; if no more check outs are available for this item, returns the String “NOT ALLOWED”; overrides LibraryItem.checkOut()

β—‹ void checkIn() // checks in this item (frees up one checkout for this item); overrides LibraryItem.checkIn()

β—‹ boolean equals(Object otherObject) // returns true if otherObject has the same instance variable(s) value(s) as this DigitalBook

● PrintBook public methods: β—‹ PrintBook(String title, String author, int numPages) // Constructs a

PrintBook object with the given title, author, and number of pages β—‹ int getNumPages() β—‹ void setNumPages(int numPages)

β—‹ String checkOut() // if this item is not already checked out, this method checks this item out and returns the loan period; if it is already checked out, returns the String “NOT ALLOWED”; overrides LibraryItem.checkOut()

β—‹ boolean equals(Object otherObject) // returns true if otherObject has the same instance variable(s) value(s) as this PrintBook

● AudioBook public methods: β—‹ AudioBook(String title, String author, double playingTime) //

Constructs an AudioBook object with the given title, author, and playing time (in hours)

β—‹ double getPlayingTime() β—‹ void setPlayingTime(double playingTime) β—‹ String checkOut() // if the max number of checkouts for this item

has not already been reached, this method checks this item out and returns the loan period; if no more check outs are available for this item, returns the String “NOT ALLOWED”; overrides LibraryItem.checkOut()

β—‹ void checkIn() // checks in this item (frees up one checkout for this item); overrides LibraryItem.checkIn()

β—‹ boolean equals(Object otherObject) // returns true if otherObject has the same instance variable(s) value(s) as this AudioBook

Example: ArrayList actors = new ArrayList(); actors.add(“Amy Adams”); actors.add(“Glenn Close”); actors.add(“Haley Bennett”); actors.add(“Gabriel Basso”); DVD dvd1 = new DVD(“Hillbilly Elegy”, actors); Magazine mag1 = new Magazine(“Time”, 435, “February 2021”); DigitalBook db1 = new DigitalBook(“Hillbilly Elegy”, “J.D. Vance”, 264); PrintBook pb1 = new PrintBook(“Hillbilly Elegy”, “J.D. Vance”, 264); PrintBook pb2 = new PrintBook(“The Warmth of Other Suns”, “Isabel Wilkerson”, 622); PrintBook pb3 = new PrintBook(“Caste”, “Isabel Wilkerson”, 496); AudioBook ab1 = new AudioBook(“Hillbilly Elegy”, “J.D. Vance”, 6.8); AudioBook ab2 = new AudioBook(“Hillbilly Elegy”, “J.D. Vance”, 6.8); ab1.equals(ab2); // returns true dvd1.equals(db1); // returns false pb2.equals(pb3); // returns false

LibraryItem[] items = new LibraryItem[8]; items[0] = dvd1; items[1] = mag1; items[2] = db1; items[3] = pb1; items[4] = pb2; items[5] = pb3; items[6] = ab1; items[7] = ab2; for (LibraryItem item : items) { System.out.println(item.checkOut()); } // =========================== // above should print: // 7 days // 7 days // 14 days // 21 days // 21 days // 21 days // 28 days // 28 days System.out.println(items[6].checkOut()); // 28 days System.out.println(items[6].checkOut()); // NOT ALLOWED items[6].checkIn(); System.out.println(items[6].checkOut()); // 28 days

Needs help with similar assignment?

We are available 24x7 to deliver the best services and assignment ready within 3-4 hours? Order a custom-written, plagiarism-free paper

Order Over WhatsApp Place an Order Online

"Do you have an upcoming essay or assignment due?


Get any topic done in as little as 6 hours

If yes Order Similar Paper

All of our assignments are originally produced, unique, and free of plagiarism.

Stuck with a Question?

Get it solved from our top experts within 8 hrs!

Ask Your Question Now!