Skip to content

Latest commit

 

History

History
37 lines (33 loc) · 971 Bytes

check-in-meeting-answers.md

File metadata and controls

37 lines (33 loc) · 971 Bytes

CSE 143

Check-in Meeting Answers

Week 1

  1. A table of answers is shown below.

    Statement Output
    var1.method1(); Soap 1/Dish 3/Soap 3
    var2.method1(); Soap 1/Fork 3
    var3.method1(); Soap 1/Bowl 3
    var4.method1(); Soap 1/Fork 3
    var5.method1(); Soap 1/Soap 3
    var6.method1(); compiler error
    var1.method2(); compiler error
    var2.method2(); Fork 2
    var3.method2(); compiler error
    var1.method3(); Dish 3/Soap 3
    var2.method3(); Fork 3
    var3.method3(); Bowl 3
  2. One possible answer is shown below.

    public void insertAt(int index, int n, int value) {
    	if (index < 0 || index > size || n < 0) {
    		throw new IllegalArgumentException();
    	}
    	for (int i = size - 1 + n; i >= index + n; i--) {
    		elementData[i] = elementData[i - n];
    	}
    	for (int i = index; i < index + n; i++) {
    		elementData[i] = value;
    	}
    	size += n;
    }