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.
Hello
.
The name of the class should be Hello
.
Be sure to include main
.
public class Hello { public static void main(String[] args) { System.out.println("Hello"); } }
(1 + 3)(2 x 7)
Write an equivalent Java expression.
Math.pow(1 + 3, 2 * 7)
(7 - 2) x 28
Write an equivalent Java expression.
(7 - 2) * Math.pow(2, 8)
String
from the userScanner input = new Scanner(System.in); String first = input.nextLine(); String second = input.nextLine(); String concat = first + second; System.out.println(concat);
String
from the userSystem.out.print/System.out.println
statementScanner input = new Scanner(System.in); String first = input.nextLine(); String second = input.nextLine(); System.out.println(first + "\n" + second);
mystery
, with the following actual parameters:
int
holding the value 5
String
holding the text foo
long
holding the value 23
double
holding the value 3.14
mystery(5, "foo", 23l, 3.14)
promptAndReadInt
which will:
"Enter an integer:"
public static int promptAndReadInt() { Scanner input = new Scanner(System.in); System.out.print("Enter an integer:"); int readIn = input.nextInt(); return readIn; }
promptAndReadIntWithPrompt
which will:
String
parameter
public static int promptAndReadIntWithPrompt(String prompt) { Scanner input = new Scanner(System.in); System.out.print(prompt); int readIn = input.nextInt(); return readIn; }
promptAndReadInt
method, this time by calling the promptAndReadIntWithPrompt
method.
public static int promptAndReadInt() { return promptAndReadIntWithPrompt("Enter an integer:"); }
readAndAddTwo
which will:
public static void readAndAddTwo() { Scanner input = new Scanner(System.in); int first = input.nextInt(); int second = input.nextInt(); System.out.println(first + second); }