Test: O Q1: Writing Java Program As depicted in the figure below, define one interface named Downloadable and five class

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Test: O Q1: Writing Java Program As depicted in the figure below, define one interface named Downloadable and five class

Post by answerhappygod »

Test O Q1 Writing Java Program As Depicted In The Figure Below Define One Interface Named Downloadable And Five Class 1
Test O Q1 Writing Java Program As Depicted In The Figure Below Define One Interface Named Downloadable And Five Class 1 (89.71 KiB) Viewed 15 times
Test: O Q1: Writing Java Program As depicted in the figure below, define one interface named Downloadable and five classes name Document, TextDocument, HTMLDocument, WebsiteManager and Test. Class HTMLDocument extends TextDocument and implements interface Downloadable. Subclass TextDocument extends abstract superclass Document. The two classes have a "composition" relationship (WebsiteManager "has an Array of Document). Class Test contains only main method. Document #title: String #size: double +Document(title:String, size:double) +toString():String interface» Downloadable timpa mass aldT TextDocument + duration (internetSpeed:int):double #length: int +TextDocument(title:String.size:double.length:int) +toString():String ADOB bowolle HTMLDocument HTMLDocment(title:String,size:double.length:int) + duration (internetSpeed:int):double Website Manager -serverName: String -documents: Document] + WebsiteManger(serverName:String, numberOfDocuments:int) + add (document:Document,index:int):void +NumURLS():int +totalDurations (internetSpeed:int):double +display() CS2301-Programming II - Final Lab Exam Semester 2 - 1442-43H Page 2 of 4

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
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply