Programming Assignment 02


Due: Week of Sep. 5 in lab


  1. Problem 1.2.14 on page 41 of your book. Name the file and program ch1sec2prob14.java. Worth 10pts. Only output a single true/false value. Hint: Use the or operation (operator '||').
    Examples:
    • Input:$ java ch1sec2prob14 10 5
      Output:true
    • Input:$ java ch1sec2prob14 3 9
      Output:true
    • Input:$ java ch1sec2prob14 42 5
      Output:false
  2. Problem 1.2.19 on page 41 of your book. Name the file and program ch1sec2prob19.java. Worth 10pts. Only output a single value. You should assume that a is less than b. You cannot use the Java class/utility Random; you must use Math.random().
    Examples:
    • Input:$ java ch1sec2prob19 3 10
      Output:6
    • Input:$ java ch1sec2prob19 3 10
      Output:8
  3. Problem 1.2.22 on page 41 of your book. Name the file and program ch1sec2prob22.java. Worth 10pts. Only output a single value. Note the equation in the book has a slight issue, either change g to be negative or change the equation to subtract g*t^2/2. The final equation would be x_0 + v_0*t - g*t^2/2.
    Examples:
    • Input:$ java ch1sec2prob22 10 10 10
      Output:-379.01649999999995
  4. Problem 1.2.29 on page 42 of your book. Name the file and program ch1sec2prob29.java. Worth 35pts. Only output a single value, do not output the day as a String. The input will be in m d y ordering!
    Examples:
    • Input:$ java ch1sec2prob29 9 1 2016
      Output:4
    • Input:$ java ch1sec2prob29 3 19 1991
      Output:2
  5. Problem 1.2.34 on page 44 of your book. Name the file and program ch1sec2prob34.java. Worth 35pts. Print three values separated by spaces. Do not assume that the values are unique! Do not use if-else statements; instead use Math.min and Math.max to assist your solution.
    Examples:
    • Input:$ java ch1sec2prob34 5 4 3
      Output:3 4 5
    • Input:$ java ch1sec2prob34 5 5 5
      Output:5 5 5
  6. Bonus. Write a program to output the truth table values for XOR or exclusive or. Please neatly format the output to show the values of a, b, and a^b where a^b is the exclusive or operation. Name the file and program ch1sec2bonus.java. Worth 10pts. Do not hardcode the answer to each a^b. Rather compute it with a boolean expression.
    Example:
    • Input:$ java ch1sec2bonus
      Output:
      aba^b
      truetruefalse
      truefalsetrue
      falsetruetrue
      falsefalsefalse


Grading

Each assignment is graded out of 100% based on a combination of the criteria listed in the assignment description and programming style (e.g., good comments and naming) -- following instructions is extremely important in computer science, train yourself to think like the computer; programming style is important to be able to communicate your solutions to another programmer; both of which you are graded upon.

Specific instructions. Failure to do these steps will result in a loss of points.

Turn in instructions. Each programming assignment is to be turned in before your lab section. You will turn in a soft copy of the assignment (.java or .zip for multiple java files) through blackboard. You will also turn in a hard copy of the assignment in your lab section with a signed coverpage (each program should start a new page of the hard copy).

If there are any discrepencies in grades please see the instructor during his office hours or by appointment (do not discuss with the lab assistants or graders).