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 8: Classes and objects
(Thu Aug 9)
Exercises: Solve the following three (3) Self-Check problems on paper and bring your sheet of paper to your section on Thursday:
-
Chapter 8, Self-Check #2: what is an object? (p548). Answer the question in your own words.
-
Chapter 8, Self-Check #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 532-538 in the book for ideas.
July 31 2012 8:00 AM
Section 7: Arrays
(Thu August 2)
Exercises: Solve the following four (4) Self-Check problems on paper and bring your sheet of paper to your section on Thursday:
-
Chapter 7, Self-Check #14: Reference semantics question (p492). Answer the question in your own words.
-
Chapter 7, Self-Check 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, Self-Check #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.
-
Chapter 7, Self-Check Problem #7: max
(p492). Write a method named max
as described. (NOTE: You can test your solution using our Practice-It system.)
July 24 2012 8:00 AM
Section 6: Random, File input
(Thu July 26)
Exercises: Solve the following three (4) 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 6, Self-Check 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.
July 17 2012 8:00 AM
Section 5: midterm review (Thu 7/19)
Exercises: Solve the following two (2) Self-Check problems on paper and bring your sheet of paper to your section on Thursday:
-
Chapter 5, Self-Check 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, Self-Check 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.")
July 10 2012 8:00 AM
Section 4: if/else
, Scanner
, String
(Thu 7/12)
Exercises: Solve the following three (3) Self-Check problems on paper and bring your sheet of paper to your section on Thursday:
-
Chapter 4, Self-Check 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, Self-Check 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.
-
String Cumulative Sum: Write a method called spaceOut
that takes a String
as a parameter and returns that String
with a space after each character (your result should have a trailing space).
Section 3: Parameters, graphics, returns
(Thu 7/5)
Correction to problem 3 of section handout
Exercises: Solve the following three (2) problems on paper and bring your sheet of paper to your section on Thursday.
-
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
.
-
Returns: List two reasons why we use returns
Jun 26 2012 8:00 AM
Section 2: Expressions, for
loops, class constants, parameters (Thu 6/28)
Exercises: Solve the following (2) problems on paper and bring your sheet of paper to your section on Thursday:
1. Write code to produce the following figure using nested loops. Show the two loop tables you used to calculate slashes based on line number and stars based on line number.
////////////////\\\\\\\\\\\\\\\\
////////////********\\\\\\\\\\\\
////////****************\\\\\\\\
////************************\\\\
********************************
2. Chapter 3, Self-Check Problem #5: MysteryTouch
(p179)
Section 1: Printing, static methods, expressions
(Thu 6/21)
Write a println statement that prints the following text:
"I like printing backslashes \\" -Nick
"You're weird" -Student
What is the value computed by the following expressions:
a) 1 + 2 * 4 + 3
b) 1 + 2.0 * 4 + 3
c) (1 + 2.0) * 4 + 3
d) "1" + 2.0 * 4 + 3
e) 1 + "2.0 * 4" + 3
f) 13 / 3
g) 13 % 3
Remember our precedence rules and left-to-right evaluation!