Lab Exam 1 Review Questions (without Answers)

The exam will require you to write code in the lab, either on the lab machines or with your own laptop. This code will be turned in via Canvas by the end of the class. It will be similar in style to the lab assignments. You may NOT reference your previous submissions, and you may NOT access the internet for any reason other than to submit your solution via Canvas. Violations of these rules will result in a 0 on the exam.

You may bring in a single 8 1/2 x 11 inch sheet of paper containing handwritten notes, and you may write on both sides of the paper.

The review below, in addition to everything you wrote for your labs, is intended to be comprehensive. All topics which could potentially be on the exam are somehow covered by this review or the labs. The one exception is JUnit tests: these will not be on the exam, since you've only had one assignment on them.

Questions

  1. Write a complete program that will print Hello. The name of the class should be Hello. Be sure to include main.
  2. Consider the following equation:
    (1 + 3)(2 x 7)
    

    Write an equivalent Java expression.

  3. Consider the following equation:
    (7 - 2) x 28
    

    Write an equivalent Java expression.

  4. Write a code snippet that will:
    1. Read in two values of type String from the user
    2. Concatenate the two values together
    3. Print out the concatenated value
  5. Write a code snippet that will:
    1. Read in two values of type String from the user
    2. Print out the two values, one per line, using only a single System.out.print/System.out.println statement
  6. Write a code snippet that calls a method named mystery, with the following actual parameters:
    1. A value of type int holding the value 5
    2. A value of type String holding the text foo
    3. A value of type long holding the value 23
    4. A value of type double holding the value 3.14
  7. Write a method named promptAndReadInt which will:
    1. Prompt the user to enter an integer, using the text "Enter an integer:"
    2. Read in an integer from the user
    3. Return the integer read in
  8. Write a method named promptAndReadIntWithPrompt which will:
    1. Prompt the user to enter an integer, using a prompt given as a String parameter
    2. Read in an integer from the user
    3. Return the integer read in
  9. Reimplement the promptAndReadInt method, this time by calling the promptAndReadIntWithPrompt method.
  10. Write a method named readAndAddTwo which will:
    1. Read in two integers from the user
    2. Add the two integers together
    3. Print out the result of the addition
    The method should not return anything.