Homework Exercises
Sections 1.2, 3.1-3.2

Due at start of next class (not the next lab), 1/31

  1. Rewrite each condition below in valid Java syntax (give a boolean expression):
    1. x > y > z

    2. x and y are both less than 0

    3. neither x nor y is less than 0

    4. x is equal to y but not equal to z

  2. Suppose gpa is a variable containing the grade point average of a student. Suppose the goal of the program is to let a student know if he/she made the Dean's list (the gpa must be 3.5 or above). Write an if... else... statement that prints out the appropriate message (either "Congratulations -- you made the Dean's List" or "Sorry you didn't make the Dean's List").

 

 

 

 

  1. Re-write each of the following statements using the operators from pg. 19 of your text.

    1. numEmployees = numEmployees + 1;

    2. totalSalary = totalSalary + salary;

    3. totalWages = totalWages + hours*payRate;

    4. balance = balance - withdrawal;

  2. Determine the value of each variable after the execution of the given segments of code (see pp. 30-32).
    1.        numA = 13;
             numB = 5;
             numC = ++numA + numB++;
          
    2.        numA = 10;
             numB = 3;
             numB += numA++;
             System.out.println ("A: " + numA-- + " B: " + ++numB);
          
  3. The prefix and postfix increment and decrement operators can be handy, but, as the book states, they should be used with care. Why is it generally not a good idea to use them in expressions (as in the last problem)?