Question: Java In this lab, you will add functionality to the LibraryItem hierarchy and add new subclasses. Use the following UML diagram as reference. Need a
Java
In this lab, you will add functionality to the LibraryItem hierarchy and add new subclasses. Use the following UML diagram as reference.



Need a code for EBook.java, Video.java, StreamingVideo.java
provided Code:
LibraryItem.java
import java.text.SimpleDateFormat; import java.util.Calendar; public abstract class LibraryItem { private String title; private String callNumber; private String format; private boolean available; private Calendar dueDate; public LibraryItem(String title, String callNumber, String format) { this.title = title; this.callNumber = callNumber; this.format = format; this.available = true; this.dueDate = null; } /** * @return the title */ public String getTitle() { return title; } /** * @param title the title to set */ public void setTitle(String title) { this.title = title; } /** * @return the callNumber */ public String getCallNumber() { return callNumber; } /** * @param callNumber the callNumber to set */ protected void setCallNumber(String callNumber) { // validate the callNumber this.callNumber = callNumber; } /** * @return the format */ public String getFormat() { return format; }
/** * @param format the format to set */ public void setFormat(String format) { this.format = format; } /** * @return the available */ public boolean isAvailable() { return available; } /** * @param available the available to set */ private void setAvailable(boolean available) { this.available = available; } /** * @return the dueDate */ public String getDueDate() { SimpleDateFormat dateFormat = new SimpleDateFormat("MMMM dd, yyyy"); return dateFormat.format(dueDate.getTime()); } /** * @param dueDate the dueDate to set */ private void setDueDate() { dueDate = Calendar.getInstance(); dueDate.add(Calendar.DATE, 21); } @Override public String toString() { String retString = ""; retString += "Title: " + getTitle(); retString += ", callNumber: " + getCallNumber(); return retString; } public boolean checkOut() { // set a dueDate for the item to be 3 weeks from checkout date // mark item as not available if (isAvailable()) { setAvailable(false); setDueDate(); return true; } else {
System.out.println("The item is unavailable and cannot be checked out"); return false; } } }
------------------------------------------------------
Book.java
public class Book extends LibraryItem { private String author; private String publisher; public Book(String title, String callNumber, String author, String publisher) { super(title, callNumber,"Book"); this.author = author; this.publisher = publisher; } /** * @return the author */ public String getAuthor() { return author; } /** * @param author the author to set */ public void setAuthor(String author) { this.author = author; } /** * @return the publisher */ public String getPublisher() { return publisher; } /** * @param publisher the publisher to set */ public void setPublisher(String publisher) { this.publisher = publisher; } public String toString() { //System.out.println("This is the Book toString method"); String retString = super.toString(); retString += ", author: " + getAuthor(); return retString; } }
-----------------------------------------------------
LibraryItemTester.java
public class LibraryItemTester { /** * @param args */ public static void main(String[] args) { // Use methods for your tests // and call the test methods from main testBook(); //testEBook(); //testVideo(); //testStreamingVideo(); //testPolymorphism(); } public static void originalLibraryItemTest() { System.out.println("*** Initial test invalid, here for reference only *** "); /* * This worked before creating a new constructor with parameters LibraryItem item1 = new LibraryItem(); */ /* System.out.println("***Test the Library Item*** "); LibraryItem item1 = new LibraryItem("Hop on Pop", "BK001", "Book"); System.out.println("item1 toString: " + item1); System.out.println("Title: " + item1.getTitle()); item1.setTitle("Green Eggs and Ham"); System.out.println("TEST: Change title to green eggs and ham"); System.out.println("Title after test: " + item1.getTitle()); */ System.out.println("*** End - Initial test *** "); } public static void testBook() { // Test the Book class System.out.println(" ***Test Book class***"); Book book1 = new Book("Hop on Pop", "BK002", "Dr. Seuss", "Randall House"); System.out.println("book1 title: " + book1.getTitle() + " , author: " + book1.getAuthor());
System.out.println("book1 toString: " + book1); System.out.println("Book1 available [true]: " + book1.isAvailable()); System.out.println("Check out book1"); book1.checkOut(); System.out.println("Book1 available [false]: " + book1.isAvailable()); System.out.println("Book1 due date: " + book1.getDueDate()); System.out.println("Checkout book1 - invalid"); book1.checkOut(); System.out.println("***End Test Book class***"); } public static void testPolymorphism() { // Polymorphism example System.out.println(" *** Polymorphism test"); Book book1 = new Book("Hop on Pop", "BK002", "Dr. Seuss", "Randall House"); LibraryItem item1 = new Book("Hop on Pop", "BK001", "Dr. Seuss", "Randall House"); System.out.println(item1); System.out.println(" *** End Polymorphism test"); }
}
Libraryltem -title: String - cal Number: String - format: String - available: boolean - dueDate: Calendar +Libraryltem(String, String, String) +checkOut(): boolean + returnltem(): boolean - getTitle(): String getCallNumber(): String +getFormato: String + is Available(): boolean + setTitle(String): void #setCallNumber(): void + setFormat(String): void - setAvailable(boolean): void + toString(): String +checkOut(): boolean + return(): boolean Book -author: String - publisher: String Video - producer: String - studio: String + Video(String, String, String, String) + Book(String, String, String, String) +getAuthor(): String + getPublisher(): String + setAuthor(): void + setPublisher(): void + toString(): String EBook Streaming Video EBook(String, String, String, String, String) Streaming Video (String, String, String, String) 1. Complete the Libraryltem class a. Implement the return() method. The method should change the value of the available variable to true. The methods should return true to indicate if the return process was successful. 2. Extend the Book class to create a new EBook subclass a. The EBook class will need to add a constructor that accepts the title, callNumber, author, publisher and format (for example PDF, EPub, Axis360). You will need to decide how to use (or not use) the super constructors (there are multiple ways to make this work) b. Override the toString method so that it includes the existing information plus the format C. Overload the checkout() method to allow user to checkout an ebook for a period of 1-4 weeks. For instance checkout(1) would add one week (7 days) to the due date. Validate the weeks, it should only be 1-4, other values invalidate the checkout process. 3. Extend the Libraryltem class to create a new video subclass a. add new attributes to the class as shown in the UML diagram b. add a constructor that accepts the title, callNumber, producer, and studio C. add setters and getters for the attributes d. Override the toString method so that it adds the producer and studio e. Override the checkout method so that the due date is one week from the checkout date 4. Extend the Video class to create a new Streaming Video subclass a. The constructor should set the format to "MP4. b. Override the toString method so that it includes the existing information plus the format C. Overload the checkout() method to allow user to checkout a streaming video for a period of 2 weeks. 5. Test your classes to make sure you can instantiate Book, EBook, Video and Streaming Video objects a. Use the LibraryltemTester included in the files and add more tests Some tests you should include, but you are not limited to For the Book hierarchy: o Create a Book object and an EBook object with the appropriate constructor Test the objects were created correctly by displaying some of the values of the book/ebook objects o Set a new author for one of the objects and display the new value o Set a new publisher for one of the objects and display the new value o Check out each of the book/ebook objects . Check out should show different due dates for each item Display isAvailable() (should be true) Return the book/ebook objects and display the availability value - it should be back to true For the Video hierarchy: o Create a video object and a Streaming Video object with the appropriate constructor o Test the objects were created correctly by displaying some of the values of the video/svideo object o Set a new producer for each of the objects and display the new value o Set a new studio for each of the objects and display the values Check out each of the video objects . Check out should show different due dates for each item Display isAvailable() (should be true) Return the video/svideo objects and display the availability value - it should be back to true
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
