COSC 1046 Assignment #8 solution


Original Work ?
Category: You will Instantly receive a download link for .ZIP solution file upon Payment


5/5 - (3 votes)

Part A: These questions are to be submitted to the instructor in the form of a Word (or Open Office) document containing the Java code and appropriate screen capture(s) of the output. Put both questions in the same word file. The file name must be in the form ASSIGN8A_YourName where ‘YourName’ is your last name followed by your first name with no space. Upload the file to CMS.
Special Problem 1: [20] Strings vs. StringBuilder Write a program that creates a String and a StringBuilder with the initial value of “Hello”. Using two for loops: a) Loop 50000 times and concatenate “hello” to the String object. b) Loop 50000 times (a different loop) and append “hello” to the StringBuilder object.
For each loop, you need to time how long it takes to complete the task. Recall that System.nanoTime() returns the current time in billionths of a second. Use this to get the time before and after each loop and then calculate how long each loop takes to complete. Report the times for each loop in milliseconds (with 3 decimal places) and how much longer the String loop took compared to the StringBuilder loop. The code is worth 10 marks and the timing analysis and observations are worth 10 marks (so make sure you write something reasonable here).
Show examples of the output from three different runs. What did you observe? What do you think it means in the context of Objects and object manipulation? How do these two forms of a string vary and how does this impact on what you are seeing?
Problem 9.1, [20] page 362 The UML diagram is worth 5 marks.
Part B: Write code and test the solutions for the following problems from the textbook. Submit the .java files for each question to CMS. The answers are due on November 28th and the programs are to be demonstrated to the Teaching Assistant (Tim) by December 1st. He will ask questions to make sure you understand the material.
Problem 9.7, [20] page 361 (No UML diagram required)
COSC 1046 (F15) – Introduction to Computer Science
Problem 9.13, [20] page 363-64 (No UML diagram required)