Computer Science 202
Introduction to Programming

Fall 2012, The College of Saint Rose

Lecture 12: Repetition
Date: Thursday, October 4, 2012


Lecture Assignment 12

Due at the start of class, Tuesday, October 9.

Nothing to turn in, but your job is to bring questions to class about past lecture assignments and programs that we can review for the exam.

You should be able to answer all of textbook's Checkpoint questions in Chapters 1-3, and all Review Questions ane Exercises at the end of Chapters 1-3 with the exception of the following: the Checkpoint exercises at the end of Section 1.7, Chapter 1 short answers 10-18 and 20-22, any questions dealing with primitive types we have not studied and used (float, byte, short, long, char), questions dealing with the Math class (p. 62) or the combined assignment operators (Section 2.6) or type conversions (Section 2.7), String methods other than length and equals, Javadoc comments, the Conditional Operator in Section 3.8, the printf method in Section 3.11.

Here is a sample "Find the errors" problem. Your task is to find 10 errors (there are more). Label each error you find, indicate the type of error (syntax error, logic error, style error), and provide a fix. The program is intended to prompt for and read in 3 integers, print a different message depending on whether the sum is 0, negative, or positive, then compute their average and display it as a floating point number with 2 digits after the decimal point.

// Crazy Program
   By J. Teresco

import java.util.Scanner

public class silly {

    public static vile main(String args[]);

      System.out.print(Enter 3 numbers:);
      int NUMBER1 = input.nextInt();
      int NUMBER2 = input.nextInt();
      int NUMBER3 = input.nextInt();

      sum = number1 + number 2 + number3;

      if sum=0 {
         System.out.println("Your sum is 0, how nice.");
      else if (sum < 0);
         System.out.println("Your sum of " sum + " is negative, how sad.");
      else (sum > 0) {
         System.out.println(sum + "is positive, and so am I.");

      Double Average = sum / 3;
      DecimalFormat f = DecimalFormat("0.0");
      System.out.println("On average, that's " + f.format(Average);