RelativeResourceManager1

RelativeResourceManager1 - { throw new...

This preview shows pages 1–4. Sign up to view the full content.

ITI1121- 2009 Midterm Marking Guidelines Question 1. Total: 6 marks A. True B. True C. False D. False E. True F. True Question 2. Total: 6 marks A. N othi ng will make this program give this output; not marked. B. linked list C. Method Calls D. Object E. http://commercialwebsite.com F. dynamic binding (or late binding) Question 3. Total: 6 marks Output: 20 1 mark 222 20 2 marks 20 1 mark Keep on Swimming 1 mark (correct new lines) 1 mark

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Question 4, Solution 1 (6 marks) public class FlexiblepArrayStackInt extends pArrayStackInt{ public void push (int n, int x[]) if (pointer + n) < head.length { int i = 0; while (i < n) { head[++pointer] = x[i++]} } else { throw new IndexOutOfBoundsException(“There is no room in the stack for n new elements”); } public int [] pop(int n) if (pointer – n) < -1 )

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: { throw new IndexOutOfBoundsException(We cannot pop more elements than there are in the stack) } else { pointer = pointer n; return head[pointer + 1]; } } - Using isEmpty() is also a good idea! Question 4, Solution 2 (6 marks) public class FlexiblepArrayStackInt extends pArrayStackInt{ public void push (int n, int x) { if (pointer + n) &lt; head.length { for (int i=0; i &lt; n; i++) { head.push(x[i]); } else { throw new IndexOutOfBoundsException(There is no room in the stack for n new elements); } } Using isEmpty() is also a good idea! public int pop(int n) { if (pointer n) &lt; -1 ) { throw new IndexOutOfBoundsException(We cannot pop more elements than there are in the stack) } else { for (int i=0; i &lt; n; i++) { temp = head.pop(); } Return temp; }...
View Full Document

RelativeResourceManager1 - { throw new...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online