Sections

Each week you will complete problem(s) to turn in at your section. These problems will earn you up to 2 out of your 3 section participation points for the week. The other point is awarded for being present in your section and participating in the discussion.

You will not be graded on whether you have a perfect solution, but on whether you have demonstrated effort. Therefore please show some work that demonstrates how you got the answer rather than just writing the answer by itself. We will be somewhat lenient about exactly how the work is shown.

Our intention is that these problems would take you up to 30 minutes each week. If you find yourself taking significantly more than this, you may stop your work and write that you worked for 30 minutes. If you have made significant progress, we will still give you credit for your work.

Section 10: Final practice (Thu May 31)

Exercises: Solve the following problem on paper and bring your sheet of paper to your section on Thursday:

  1. Inheritance. Assume that the following classes have been defined:
    public class George extends Sally {
        public void method2() {
    	System.out.println("george 2");
        }
    }
    
    public class Fred {
        public void method1() {
    	System.out.println("fred 1");
        }
    
        public void method2() {
    	System.out.println("fred 2");
        }
    
        public String toString() {
    	return "fred";
        }
    }
    
    public class Harold extends Sally {
        public String toString() {
    	return "harold";
        }
    }
    
    public class Sally extends Fred {
        public void method1() {
    	System.out.println("sally 1");
        }
    
        public String toString() {
    	return "sally";
        }
    }            
    			
    Consider the following code fragment:
    Fred[] elements = {new Sally(), new Fred(), new George(), new Harold()};
    for (int i = 0; i < elements.length; i++) {
        System.out.println(elements[i]);
        elements[i].method1();
        elements[i].method2();
        System.out.println();
    }
    			
    What output is produced by this code? (write the output as a series of 3-line columns in order from left to right)

Section 2: Expressions, for loops (Thu 4/5)

Exercises: Solve the following two (2) Self-Check problems on paper and bring your sheet of paper to your section on Thursday:

  1. Chapter 2, Self-Check Problem #2 (p117), solve expressions (a) - (e); from 2 + 3 * ... through (18 - 7) * ...
  2. Chapter 2, Self-Check Problem #3 (p118), solve expressions (a) - (c); from 4.0 / 2 * ... through 12 / 7 * ...
  3. Chapter 2, Self-Check Problem #22: reading for loop code (p121)

For the first two problems, please show some work rather than just writing the answer. Write out sub-expressions as you compute their values, and circle or underline operands to show precedence, as is done on page 69-70 of the textbook. You may use a calculator if you want, though one shouldn't be necessary for these problems. For example:

2 + 19 % 5 - 11 * (5 / 2)

2 + 19 % 5 - 11 * 2

2 + 4      - 11 * 2


2 + 4      - 22

6          - 22

-16