Test: O Q1: Writing Java Program As depicted in the figure below, define one interface named Downloadable and five class
Posted: Tue May 24, 2022 7:54 am
Description interface Downloadable: Document: ● tales of cats) duration(): takes an internet speed and returns the download duration title: title of this document size: size of this document ● Document(title:String, size:double): constructor to initialize the title and size with the received parameters. ● toString(): returns a string containing all information of the Document TextDocument: length: length of text document TextDocument(title:String,size:double,length:int): constructor to initialize the title, size, and length with the received parameters. .toString(): returns a string containing all information of the Text document. HTMLDocument: . Create a final class called HTMLDocument which is a downloadable text document ● HTMLDocment(title:S ing,size:double,length:int): constructor to initialize title, size, and length with the received parameters. ♥ duration (internetSpeed:int):double: return the calculated duration based on the following: the document size divided by the Internet speed, multiplied by length divided by 1000. WebsiteManager: ● serverName: name of servers documents: Array of type Document to store list of Document (TextDocument and HTMLDocument). Website Manager(String serverName, int numberOfDocuments):constructor to initialize the serverName and numberOfDocuments (size of thr array) with the received parameters. add (document: Document, index: int): a method which takes a document and an index, and puts the document at the specified index in the array. Use try-catch statement to handle the ArrayIndexOutOfBoundsException which occurs when the index is out of range of an array, and display an information of that exception. . NumURLS(): returns a number of URLs of all downloadable documents. • totalDurations(internetSpeed:int): takes an Internet speed and returns the sum of durations of all downloadable documents. hint: use downcasting. • display(): prints all information of documents by calling toString() method. Page 3 of 4 CS2301-Programming II - Final Lab Exam Semester 2 - 1442-43H ●
Test: Implement Test class with main method: ● Create an object of type WebsiteManager name it wm (serverName= www.mysite.com numberOfDocuments= 3). . Create all the objects that shown in the following table and pass them as a parameter to the method "add" of wm object: Index title size length 0.3 1200 0 document1.txt 1 2 Type of object TextDocument HTMLDocumen. hdocument1.html HTMLDocument hdocument2.html HTMLDocument hdocument3.html document2.txt. TextDocument. TextDocument. document 3.txt 0.4 1500 1.0 3000 4000 1.0 0.2 1300 0.5 1600 3 . Display all information of the documents of wm object by calling the method display. Print the number URLs of all downloadable documents and the sum of durations of all downloadable (documents internetSpeed=2). Sample output: java.lang.ArrayIndexOutOfBoundsException: 4 3 java.lang.ArrayIndexOutOfBoundsException: title: documentl.txt:ssin size: 0.30MB length: 1200 words title: hdocument1.html size: 0.40MB length: 1500 words title: hdocument3.html size: 1.0 OMB length: 4000 words Web Manager Info: Number of URLS: 2 Total Durations: 2-20s BUILD SUCCESSFUL (total time: 0 seconds) Page 4 of 4 CS2301-Programming II - Final Lab Exam Semester 2 - 1442-43H 2 4