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:

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
3line columns in order from left to right)
May 20 2012 11:30 AM
Section 9: Classes and objects
(Thu May 24)
Exercises: Solve the following three (3) SelfCheck problems on paper and bring your sheet of paper to your section on Thursday:

Chapter 8, SelfCheck #2: what is an object? (p548). Answer the question in your own words.

Chapter 8, SelfCheck #15: problems with constructor (p549). Write the two problems with the constructor shown, and then show a corrected version that does not contain these two problems.

TimeSpan
Object: A TimeSpan
object stores a span of time in hours and minutes (for example, the time span between 8:00am and 10:30am is 2hours, 30 minutes). The description implies that a TimeSpan
object stores hours and minutes. What would be an alternative way of storing the same information? Are there any reasons why one would be better than the other? What would happen if you wanted a method that added hours and minutes to the TimeSpan
object? See pages 532538 in the book for ideas.
May 14 2012 10:30 AM
Section 8:
(Thu May 17)
Exercises: Solve the following two (2) SelfCheck problems on paper and bring your sheet of paper to your section on Thursday:

Chapter 7, SelfCheck #14: Reference semantics question (p492). Answer the question in your own words.

Chapter 7, SelfCheck #15: Reference semantics mystery (p492). Please show your work and circle your final output so it is clear which is the answer vs. intermediate work.
May 8 2012 12:30 PM
Section 7: Arrays
(Thu May 10)
Exercises: Solve the following three (3) SelfCheck problems on paper and bring your sheet of paper to your section on Thursday:

Random
: Write code that generates a random...

integer between 0 and 10 inclusive.

integer between 11 to 99 inclusive.

integer between 2 and 2 inclusive.

odd integer (not divisible by 2) between 50 and 99 inclusive.

Chapter 7, SelfCheck Problem #24: array simulation (p495). Write the final contents of each array after the method is finished executing. Show your work by writing the arrays' initial contents and then crossing out elements as their values change.

Chapter 7, SelfCheck Problem #7: max
(p492). Write a method named max
as described. (NOTE: You can test your solution using our PracticeIt system.)
May 2 2012 12:30 PM
Section 6: File input/output
(Thu May 3)
Exercises: Solve the following three (3) SelfCheck problems on paper and bring your sheet of paper to your section on Thursday:

Chapter 6, SelfCheck Problems #8, #9, and #10: File processing (p418). For each of the three problems, write the output from the code shown. You do not need to show your work; just the answer.
Apr 23 2012 7:00 AM
Section 5: while
, midterm review
(Thu Apr 26)
Exercises: Solve the following two (2) SelfCheck problems on paper and bring your sheet of paper to your section on Thursday:

Chapter 5, SelfCheck Problem #3: while
loop mystery (p358). Write the output of each call. Show your work by writing each value that each variable has as the code is running. For each call, make a table showing the values that x
and y
have as you execute the while
loop for that particular call. For example, for the first two calls, the table look like this:
mystery(1); mystery(6);
x y z x y z
_____________ _____________
1 1 0 6 1 0
... ...

Chapter 5, SelfCheck Problem #27: Logical Assertions (p366). Turn in a table or list with your answers. For each of the five labeled points in the program, write ALWAYS (A), NEVER (N), or SOMETIMES (S) for each of the three assertions. In addition to this, show your work by explaining very briefly why you wrote the answer you wrote for each point and assertion. (Example: You could write something like, "for Point C, assertion "k > j
", the answer is SOMETIMES because the value of k
is generated by a Random
object so it could have any value.")
Apr 16 2012 12:00 PM
Section 4: if/else
, Scanner
, return
(Thu 4/19)
Exercises: Solve the following four (4) SelfCheck problems on paper and bring your sheet of paper to your section on Thursday:

Chapter 4, SelfCheck Problem #3: ifElseMystery1
(p290). The body of the method has an if, an else, and then a second if. For each call, show your work by writing which of these three blocks are entered for the given parameter values; then write the eventual output of the call.

Chapter 4, SelfCheck Problem #1: logical expressions (p289). This problem asks you to convert English sentences into logical tests. For example the sentence, "x is a positive integer," could be converted into the logical test, x > 0
. Solve the sentences numbered (a), (e), (g), and (l). These are the ones that begin as follows:
z
is odd.
y
is a multiple of ...
y
is greater in magnitude than ...
x
is closer in value to y
than ... (Hint: Use the Math.abs
method to help find the difference between two numbers.)
Write a logical expression for each of the above bullets. You do not need to show your work for this problem.

Absolute value: Write a method called abs
that given an integer, computes and returns its absolute value. For example, abs(3)
and abs(3)
would return 3. You may not call Java's Math.abs
method.

Returns: List two reasons why returns are used.
Apr 9 2012 4:30 PM
Section 3: Parameters, graphics
(Thu 4/12)
Exercises: Solve the following three (3) SelfCheck problems on paper and bring your sheet of paper to your section on Thursday. Show your work, such as by writing a table of what values are passed for each parameter to each call. Circle your final answer/output so it's clear which part is the answer vs. intermediate work.

Chapter 3, SelfCheck Problem #5:
MysteryTouch
(p179)

Chapter 3, SelfCheck Problem #4:
MysteryWho
(p178)

Graphics Problem:
Write the statements to reproduce this image:
The top left corner is at (0,0). The width and height of the square and circle are each 50 pixels. The square is black and the circle is red. Assume that you have access to a Graphics
object named g
.
Section 2: Expressions, for
loops
(Thu 4/5)
Exercises: Solve the following two (2) SelfCheck problems on paper and bring your sheet of paper to your section on Thursday:

Chapter 2, SelfCheck Problem #2 (p117), solve expressions (a)  (e); from
2 + 3 *
... through (18  7) *
...

Chapter 2, SelfCheck Problem #3 (p118), solve expressions (a)  (c); from
4.0 / 2 *
... through 12 / 7 *
...

Chapter 2, SelfCheck Problem #22: reading for loop code (p121)
For the first two problems, please show some work rather than just writing the answer. Write out subexpressions as you compute their values, and circle or underline operands to show precedence, as is done on page 6970 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
Mar 23 2012 7:00 AM
Section 1: Basic Java, static methods
(Thu Mar 29)
No problems are due for the first week's section.