Sections

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.

Section 9: Final Exam, part A (Thu Aug 20)

Good luck!

Section 8: Classes and objects (Thu Aug 13)

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

  1. Chapter 8, Self-Check #2: what is an object? (p564). Answer the question in your own words.

  2. Chapter 8, Self-Check #4: reference mystery (p564).

  3. 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.

Section 7: Arrays (Thu Aug 7)

Exercises: Solve the following three (3) problems on paper and bring your sheet of paper to your section on Thursday:

  1. 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.

  2. 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.

  3. Style Practice: Consider the following method, which takes an array that is always length 4 as a parameter and returns the sum and max value of the array.
    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.

Section 6: File input/output (Thu Jul 30)

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

  1. Please consider filling out this mid-quarter evaluation survey. It should only take about 5 minutes to complete. It's anonymous, so it's not required to receive credit for section.
  2. 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.

  3. Style Practice: Consider the following piece of code, which prints out the sum of the positive numbers that appear in a file. Assume the input Scanner has been declared somewhere earlier in the program.
      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.

Section 5: 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:

  1. Chapter 5, Self-Check Problem #14: boolean expressions (p371-2). Solve expressions (c), (d), and (k)

  2. 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.")

  3. 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
    ...                        ...
    						
  4. 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.

Section 4: 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:

  1. Programming Exercise 4.1: fractionSum (p305). Find the prompt and check your answer on Practice-It.
  2. Programming Exercise 4.12: printTriangleType (p307). Find the prompt and check your answer on Practice-It.
  3. Style Practice: Consider the following piece of code, which prompts a user about the number of friends they have and prints a corresponding message. Assume the console Scanner has been declared somewhere earlier in the program.
      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.

Section 3: parameters, graphics (Thu July 9)

Exercises: Solve the following three (3) problems on paper and bring your sheet of paper to your section on Thursday:

  1. Parameter Mystery, Consider the following program:
      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.
  2. Programming Exercise 3G.1 (p223) You can check your work for this problem using Practice-It.
  3. Style Practice: Consider the following piece of code
       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.

Section 2: Expressions, 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:

  1. Chapter 2, Self-Check Problem #2 (b) (p119), solve the following expression (see note below):
    	14 / 7 * 2 + 30 / 5 + 1
          
  2. Chapter 2, Self-Check Problem #3 (d) (p120), solve the following expression (see note below):
    	4 * 3 / 8 + 2.5 * 2
          
  3. Chapter 2, Self-Check Problem #4 (i) (p120), solve the following expression (see note below):
            4 + 1 + 9 + "." + (-3 + 10) + 11 / 3
        
  4. Chapter 2, Self-Check Problem #28 (p125), What is the output of the following sequence of loops?
          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();
          }
        
  5. Style Practice: Consider the following program
       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
				

Section 1: Basic Java, Static Methods (Thu June 25)

Complete by 8:30AM, Thursday, June 25, 2014

Section assignments will show here as they are assigned.