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.
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
β ArrayList
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
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