{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

midterm-2-solutions-form-A cse114 official

midterm-2-solutions-form-A cse114 official - String key =...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Name: Recitation Section: Stony Brook ID #: CSE 114 Midterm 2 Solutions (Form A) Question Part/Section Answer Points 1 A, B, F, G, H (3 points each) 15 2 False 5 3 A 5 4 D 5 5 Automatic credit due to error in question 5 6 D 5 7 False (Arrays hold same-type variables) 5 8 False (array length tracks total space available) 5 9 True 5 10 B 5 11 D (The two interfaces only contain 3 methods) 5 12 D, E, G (4 points each) 12 13 Should have been D; your TA can correct this 5 14 1 Write your code on the back of this sheet 3 2 Write your code on the back of this sheet 5 3 Write your code on the back of this sheet 10 15 1 123 3 2 1211 3 3 1212110200 3 4 0112345021 3 5 12345345012 3 Total Points 115
Background image of page 1

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

View Full Document Right Arrow Icon
Solutions to Question 14: public String getCorrectAnswer () // part 1 { return correctAnswer; } public String getAnswerKey () // part 2
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: { String key = “”; for (int i = 0; i < questions.size(); i++) { TrueFalseQuestion x = questions.get(i); key += (i + 1) + “. “ + x.getCorrectAnswer() + “\n”; } return key; } public String getBreakdown () // part 3 { String result = “”; int correct = 0, incorrect = 0, blank = 0; for (int i = 0; i < questions.size(); i++) { TrueFalseQuestion x = questions.get(i); if (x.hasBeenAnswered() == false) blank++; else if (x.answerIsCorrect() == true) correct++; else incorrect++; } result = “Correct: ” + correct + “\n”; result += “Incorrect: ” + incorrect + “\n”; result += “Blank: ” + blank; return result; }...
View Full Document

{[ snackBarMessage ]}