CS367 Homework 1
|
QuestionsHomework assignments must be done individually. Collaboration on homework assignments is not allowed. Point allocation: 25%/25%/50% Question 1:Consider the following code fragment that is intended to remove every other item from a List<String> object. For example, given the list [ "Ben", "Beck", "Eric", "Vidya", "Jason", "Xiaoming" ], it should remove "Ben", "Eric", and "Jason" and leave the list as just [ "Beck", "Vidya", "Xiaoming" ]. for (int i = 1; i <= words.size(); i += 2) { words.remove(i); }
Question 2:Assume that the ArrayList constructor initially reserves enough room to store ten elements without resizing. When resizing is needed, assume that the larger array is three times as big as the old one.
Question 3:Consider the following pseudo-code: void main( ) { println("main enter"); a(); try { c(); if (v4 == true) throw new Exc4(); } catch (Exc4 ex) { println("main caught Exc4"); } catch (Exc2 ex) { println("main caught Exc2"); } catch (Exc1 ex) { println("main caught Exc1"); } println("main exit"); } void a( ) { println("a enter"); try { b(); } catch (Exc1 ex) { println("a caught Exc1"); } println("a exit"); } void b( ) { println("b enter"); if (v2 == true) throw new Exc2(); println("b exit"); } void c( ) { println("c enter"); try { d(); if (v4 == true) throw new Exc3(); } catch (Exc3 ex) { println("c caught Exc3"); if (v3 == true) throw new Exc4(); } catch (Exc4 ex) { println("c caught Exc4"); } println("c exit"); } void d( ) { println("d enter"); if (v1 == true) throw new Exc1(); if (v3 == true) throw new Exc3(); if (v5 == true) throw new Exc5(); println("d exit"); } For the each part below determine the complete output that would be generated if the pseudo-code above was run with the values of the v variables as specified below. Assume the exception classes Exc1, Exc2, Exc3, Exc4, and Exc5 each extend RuntimeException. If an exception is passed out of main, show the output of the runtime environment as "Program terminated due to Exception ExcN ", where N is the particular exception number.
|
Handing inPlease include your name at the top your file. Put your answers to all questions into one file named Homework1 with the appropriate file extension, e.g., Homework1.pdf (see File Format for acceptable file formats). Electronically submit your work to the Homework 1 tab on Canvas. |
Last Updated: 1/11/2018 © 2016-18 Beck Hasti and Charles Fischer |