Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

java For this assignment, you are given an abstract class Library Item (Libraryltem.java a). You must complete the following: 1. Add an equals method to

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedjava

For this assignment, you are given an abstract class Library Item (Libraryltem.java a). 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: Item Type Max # checkouts per item DVD 1 1 Magazine Digital Book Print Book Loan Period 7 days 7 days 14 days 21 days 28 days 3 1 Audio Book 2 Library Item public method to add: o boolean equals (Object otherObject) // returns true if otherObject has the same instance variable(s) value (3) 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 (3) value (3) as this DVD Magazine public methods: 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 get PublicationDate() o void set PublicationDate (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 (3) value (3) as this Magazine . o . 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 (3) value (3) 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 numBages) . 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 (3) value (3) as this DigitalBook PrintBook public methods: PrintBook (String title, String author, int numBages) // 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 (3) value (3) 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 (3) value (3) as this AudioBook . o Example: ArrayList actors = new ArrayList(); actors.add("Amy Adams"); actors.add("Glenn Close"); actors.add("Haley Bennett"); actors.add("Gabriel Ba330"); DVD dvdl = new DVD ("Hillbilly Elegy", actors); Magazine mag1 = new Magazine ("Time", 435, "February 2021"); DigitalBook dbl = new DigitalBook ("Hillbilly Elegy", "J.D. Vance", 264); PrintBook pl = 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 abl = new AudioBook ("Hillbilly Elegy", "J.D. Vance", 6.8); AudioBook ab2 = new AudioBook ("Hillbilly Elegy", "J.D. Vance", 6.8); abi.equals (ab2); // returns true dvdl.equals (dbl); // returns false pb2.equals (pb3); // returns false Library Item[] items = new Library Item [8]; items [0] = dvdl; items [1] = magi; items [2] = db1; items [3] poi; items [4] pb2; items [5] pb3; items [6] = abi; 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 public abstract class LibraryItem { private String title; private boolean checkedout; public LibraryItem(String title) { this.title = title; checkedout = false; } public String getTitle() { return title; } public boolean ischeckedout() { return checkedout; 3 public void setcheckedout(boolean checkedout) { this.checkedout = checkedout; 3 public abstract string checkout(); public void checkin() { checkedout = false; } public String tostring() { return title; } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

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

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

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

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

the "Where" SQL clause can be used to link two tables.

Answered: 1 week ago