CPS 4 Fall 2001 : Exam 1 Review


Binary Numbers

  1. Given that a single binary digit, or bit, can represent two distinct numbers, 1 or 0, and two bits can represent four distinct numbers, 00, 01, 10, or 11, how many different numbers can be represented by 10 bits?
    1. 256
    2. 512
    3. 1024
    4. 2048
       
  2. If one of those 10 bits is used to represent a numberĘs sign, i.e., if the number is positive or negative, instead of another digit, then how many different numbers can be represented by 10 bits (9 bits and one sign bit)?
    1. 255
    2. 511
    3. 1023
    4. 2047
       
  3. Which of the following binary numbers correctly represents the decimal number 15?
    1. 11111
    2. 10001
    3. 1111
    4. 1101

Drawing

  1. Stoplight
    Write an applet that displays a picture of a stoplight. The stoplight should be centered within the applet and the size of each of its lights should be one-fourth that of the appletĘs standard size 400x400. The top circle should be red, the center circle should be yellow, and the bottom circle should be green. Finally, a white rectangle should surround the three circles exactly.
      
  2. Pie Chart
    Write an applet that displays a pie chart showing the percentages of students of each class taking this course. The pie chart should be centered within the applet and its size should be that of the appletĘs standard size 400x400. The pie should be divided according to the following percentages:
    • first years: 40 percent
    • sophomores: 10 percent
    • juniors: 10 percent
    • seniors: 40 percent

    The individual wedges should be colored accordingly:

    • first years: red
    • sophomores: blue
    • juniors: violet
    • seniors: green

Problem Solving

  1. Describe the procedure for saving your classwork and updating your course web page
     
     
  2. The United States Centers for Disease Control, CDC, determines obesity according to a body mass index, BMI, computed as follows:
    BMI = (weight in kilograms) / (height in meters)2

    An index of 27.8 or greater for men or 27.3 or greater for non-pregnant women is considered obese. Write java code that, given height and weight in metric units, determines the BMI.

    public Applet ()
    {
        double weightKG = 100.0;
        double heightM = 2.1;
        // enter Java code here to calculate BMI
    }
     
  3. Now write your code such that the height and weight can be calculated given American units. Note that one meter is 39.37 inches, one inch is 2.54 centimeters, one kilogram is 2.2 pounds, and one pound is 454 grams.

public Applet ()
{
    double weightLB = 220.0;
    double heightF = 6.1;
    // enter Java code here to calculate BMI
}