Each week problem(s) will be assigned to you that are due at the beginning of section. Three points will be awarded for being present in your section and turning in the weekly problems (graded on effort, not correctness). You must attend section to earn credit for the weekly section problems.
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.
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? (p564). Answer the question in your own words.
Chapter 8, Self-Check #4: reference mystery (p564).
Chapter 8, Self-Check #18: problems with constructor (p566). Write the two problems with the constructor shown, and then show a corrected version that does not contain these two problems.
Exercises: Solve the following three (3) problems on paper and bring your sheet of paper to your section on Thursday:
Chapter 7, Self-Check Problem #28: array simulation (p509). 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 Problem #10: max
(p506). Write a method named max
as described. Find the prompt and check your answer on Practice-It.
public static int[] sumAndMax(int[] array) { int sum = 0; sum += array[0]; sum += array[1]; sum += array[2]; sum += array[3]; int max = array[0]; max = Math.max(array[1], max); max = Math.max(array[2], max); max = Math.max(array[3], max); int[] results = new int[2]; results[0] = sum; results[1] = max; return results; }
This code would receive full external correctness, but not full internal correctness. List all style issues that you can find.
Exercises: Solve the following four (4) Self-Check problems on paper and bring your sheet of paper to your section on Thursday:
Chapter 6, Self-Check Problems #12, #13, and #14: File processing (p429). For each of the three problems, write the output from the code shown. You do not need to show your work; just the answer.
double total = 0; while (input.hasNext()) { double num = input.nextDouble(); if (num > 0) { total += num; } if (!input.hasNextDouble()) { System.out.println("Total sum of positive numbers: " + total); } }
This code would receive full external correctness, but not full internal correctness. List all style issues that you can find.
while
, Random
, boolean
, Midterm Review
(Thu Jul 24)
Exercises: Solve the following four (4) Self-Check problems on paper and bring your sheet of paper to your section on Thursday:
Chapter 5, Self-Check Problem #14: boolean
expressions (p371-2). Solve expressions (c), (d), and (k)
Chapter 5, Self-Check Problem #27: Logical Assertions (p375). 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.")
Chapter 5, Self-Check Problem #3: while
loop mystery (p368-9). Write the output of the first three (3) calls -- mystery(1), mystery(6), mystery(19). 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 ... ...
Random
: Write code that generates a random...
integer between 0 and 10 inclusive.
integer between 11 to 99 inclusive.
odd integer (not divisible by 2) between 50 and 99 inclusive.
if/else
, Scanner
, return
(Thu July 16)
Exercises: Solve the following three (3) problems on paper and bring your sheet of paper to your section on Thursday:
fractionSum
(p305). Find the prompt and check your answer on Practice-It.
printTriangleType
(p307). Find the prompt and check your answer on Practice-It.
System.out.print("How many friends do you have? ") double friends = console.nextDouble(); if (friends < 50) { System.out.println("You are friends with " + friends / 7000000000 + " percent of the world."); System.out.println("You need to get more friends!"); } else if (friends >= 50 && friends < 250) { System.out.println("You are friends with " + friends / 7000000000 + " percent of the world."); System.out.println("You have an average number of friends."); } else if (friends >= 250) { System.out.println("You are friends with " + friends / 7000000000 + " percent of the world."); System.out.println("Whoa there! You have a lot of friends."); }
This code would receive full external correctness, but not full internal correctness. List all style issues that you can find.
Exercises: Solve the following three (3) problems on paper and bring your sheet of paper to your section on Thursday:
public class ParameterMystery { public static void main(String[] args) String head = "shoulders"; String knees = "toes"; String elbow = "head"; String eye = "eyes and ears"; String ear = "eye"; touch(ear, elbow); touch(eye, ear); touch(head, "knees " + knees); } public static void touch(String elbow, String ear) { System.out.println("touch your " + ear + " to your " + elbow); } }Make a table that shows what value is being passed to
elbow
and
ear
for each of the three calls and then indicate the output produced by
the program.public static void main(String[] args) { int result = 0; result = factorial(5, result); } // Calculates the factorial public static int factorial(int number, int result) { result = 1; for (int i = 2; i <= number; i++) { result = result * i; } return result; }
This method would receive full external correctness, but not full internal correctness. List all style issues that you can find.
for
loops
(Thu July 2nd)
Exercises: Solve the following five (5) Self-Check problems on paper and bring your sheet of paper to your section on Thursday:
14 / 7 * 2 + 30 / 5 + 1
4 * 3 / 8 + 2.5 * 2
4 + 1 + 9 + "." + (-3 + 10) + 11 / 3
for (int i = 1; i <= 2; i++) { for (int j = 1; j <= 3; j++) { for (int k = 1; k <= 4; k++) { System.out.print("*"); } System.out.print("!"); } System.out.println(); }
public static void slash() { for (int a = 1; a <= SIZEOFFIGURE; a++) { for (int b = 1; b <= -1 * a + SIZEOFFIGURE; b++) { System.out.print("+"); } for (int c = 1; c <= 1; c++) { System.out.print("/"); } for (int d = 1; d <= a - 1; d++) { System.out.print("+"); } System.out.println(""); } }
and SIZEOFFIGURE is a class constant declared earlier in the program. When SIZEOFFIGURE is 4, this method produces the following output:
+++/ ++/+ +/++ /+++
This method would receive full external correctness, but not full internal correctness. List all style issues that you can find.
For the first three 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 71-72 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
Complete by 8:30AM, Thursday, June 25, 2014