Quiz 1

CSC120: Programming I - Fall 2000
Christian A. Duncan
(305) 284-2254
csc120@ocala.cs.miami.edu


Name: ____________________

TA: ______________________

Basic concepts (One Point Each)

1) Which TWO of the following identifiers are not valid:
(a) hello (b) i2x (c) S_1
(d) 3xy (e) ru3f (f) good-bye

2) Which TWO of the following assignments are not valid:
(a) int x = 3; (b) float y = 3.0;
(c) boolean isTrue = 0; (d) String name = "Christian";
(e) int lastName = "Duncan"; (f) float z = 3;

3) Which of the following comments is not valid (just ONE):
(a) // Comment #1... is this one acceptable?
(b) // Comment #2... may be a bit trickier */ or is it?
(c) /* Comment #3... maybe it is this one */ or maybe not?
(d) /* Comment #4... they all seem to be correct? /* but are they */

Understanding Object-Oriented Concepts (One Point Each)

Look at the following code. You do not need to understand how it works, simply what the terms mean.
import java.io.*;

// A "fake" class that keeps track of BankTellers
public class BankTeller {
  static int maximumSalary;
  int salary;
  String name;

  // This method increases the maximum salary for all BankTeller's
  public static void increaseMaximumSalary(int amount) {
     maximumSalary += amount;
  }

  // This method returns a particular BankTeller's salary
  public int getSalary() {
    return salary;
  }

  // This method prints out a BankTeller's name
  public void printName() {
    System.out.println("My name is " + name);
  }
}
3) What is the name of the class? _____________________

4) There are four variables associated with this class. What are they? (Hint: One is an argument of a method)


5) There are three methods associated with this class. What are they?


6) What is the name of the filename (i.e., xxxx.yyyy) that this program should be saved as? (Big Hint: It has something to do with the class name)


Understanding Code (Two Points Each)

For these two problems if you are uncomfortable with your answer, particularly the last problem, which by the way, is supposed to be tricky for some of you, show your work. This means, go through the program step by step and write down the variable values as the change. Give as much detail as you can. If I feel you understood what the program was trying to do, it will make it that much easier for me to give partial credit.

7) What is the output of the following program?
I.e., when "java Foo" is executed.

import java.io.*;

// The following program does what????
public class Foo {
  public static void main(String[] args) {
    int numberOne = 2;
    int numberTwo = 10;
    if ((numberOne + numberTwo) < 0) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }
}
8) What is the output of the following program?
I.e., when "java Foo" is executed.
import java.io.*;

// The following program takes two numbers and????
public class Foo {
  public static void main(String[] args) {
    int numberOne = 2;
    int numberTwo = 10;
    while (numberOne > 0) {
       numberTwo--;
       numberOne--;
    }
    System.out.println("The value of numberTwo is " + numberTwo);
  }
}