CS367 Homework 2
| ||
AnnouncementsCheck here periodically.
| ||
QuestionsHomework assignments must be done individually. Collaboration on homework assignments is not allowed. Question 1:Consider the following pseudo-code: void main( ) { println("main enter"); a(); try { b(); c(); } catch (Exc1 exc) { println("main caught Exc1"); } catch (Exc3 exc) { println("main caught Exc3"); } println("main exit"); } void a( ) { println("a enter"); if (var0) throw new Exc3(); println("a exit"); } void b( ) { println("b enter"); try { if (var1) c(); else throw new Exc1(); } catch (Exc2 exc) { println("b caught Exc2"); } finally { println("b finally"); } println("b exit"); } void c( ) { println("c enter"); try { if (var2) throw new Exc2(); if (var3) throw new Exc3(); } catch (Exc3 exc) { println("c caught Exc3"); } println("c 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 var variables as specified below. Assume the exception classes Exc1, Exc2, and Exc3 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.
Question 2:Complete the following Java method, forceAdd, as part of the SimpleArrayList<E> class. Do not check pos yourself! Instead, you must call add and catch and handle any IndexOutOfBoundsExceptions that result. public void forceAdd(int pos, E item) { // Add the item to the list at position pos just as the ListADT.add // method would do. However, if the call to add throws an // IndexOutOfBoundsException, add the item to the end of the list. } | ||
Handing inPlease include your name at the top your file. Put your answers to both questions into one file named Homework2 with the appropriate file extension, e.g., Homework2.pdf (see File Format for acceptable file formats). Electronically submit your work to the Homework 2 Dropbox on Learn@UW. | ||
Last Updated: 6/15/2014 © 2014 Beck Hasti |