# final_key - 1 of 9 CSE 142, Winter 2008 Final Exam Key 1....

This preview shows pages 1–3. Sign up to view the full content.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 1 of 9 CSE 142, Winter 2008 Final Exam Key 1. Expressions Expression 102 / 20 / 2.0 * 2 + 100 / 30 / 2 27 % 4 + 6 % 6 + 5 % 20 "\"" + (3 + 3 * 3 + "" + 3 + 3 * 3 + "\"") !(42 > 10 && (2 > 3 || 4 < 5)) (2 == 3) == (4 == 5) Value 6.0 8 "\"1239\"" false true 2. Array Mystery Expression int a1 = {1, 8, 3, 8, 7}; arrayMystery(a1); int a2 = {4, 0, 0, 4, 0, 0, 4, 0}; arrayMystery(a2); int a3 = {9, 8, 7, 6, 4, 6, 2, 9, 9}; arrayMystery(a3); int a4 = {42}; arrayMystery(a4); int a5 = {5, 5, 5, 6, 5, 5, 5}; arrayMystery(a5); Final Contents of Array [1, 10, 5, 10, 7] [4, 0, 2, 4, 0, 2, 4, 0] [11, 8, 7, 8, 6, 8, 2, 9, 11] [44] [7, 7, 7, 8, 7, 7, 7] 3. Inheritance Mystery Lois a Meg a Lois b Meg Lois a Meg a Stewie a Lois a Meg a Stewie a Brian b Brian Stewie Meg a Meg b Meg Lois a Meg a Lois a Meg a Brian b Brian 2 of 9 4. File Processing (five solutions shown) public static void pizza(Scanner input) { while (input.hasNextLine()) { String line = input.nextLine(); Scanner lineScan = new Scanner(line.toLowerCase()); double boxes = 0.0; int totalBoxes = 0; while (lineScan.hasNext()) { totalBoxes++; String box = lineScan.next(); if (box.equals("whole")) { boxes++; // 1 } else if (box.equals("half")) { boxes += 0.5; // 1/2 } else { // "slice" boxes += 0.125; // 1/8 } } System.out.println((int) Math.ceil(boxes) + " / " + totalBoxes + " pizza boxes used"); } } public static void pizza(Scanner input) { while (input.hasNextLine()) { Scanner lineScan = new Scanner(input.nextLine().toLowerCase()); int slices = 0; int totalBoxes = 0; while (lineScan.hasNext()) { totalBoxes++; String box = lineScan.next(); if (box.equals("whole")) { slices += 8; } else if (box.equals("half")) { slices += 4; } else { slices++; } } // round up to an even box int boxes = slices / 8; if (slices % 8 != 0) { boxes++; } System.out.println(boxes + " / " + totalBoxes + " pizza boxes used"); System....
View Full Document

## This note was uploaded on 04/08/2008 for the course CSE 142 taught by Professor Martystepp during the Winter '07 term at University of Washington.

### Page1 / 9

final_key - 1 of 9 CSE 142, Winter 2008 Final Exam Key 1....

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online