SYSC 2004 Midterm Fall 2007

SYSC 2004 Midterm Fall 2007 - Carleton University...

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

View Full Document Right Arrow Icon
Page 1 of 12 Carleton University Department of Systems and Computer Engineering SYSC 2004 A - Object-Oriented Software Development - Fall 2007 Midterm Exam 1 – October 3 rd , 2007 Sample Solutions – v2 Please read these instructions before you answer any of the exam questions: 1. There are two questions worth 30 marks on 12 pages. 2. The midterm exam is closed book. Calculators are not permitted. 3. Do not talk to any other students from the time the exam begins until your completed exam has been submitted and you have left the exam room. 4. Ask a question only if you believe there is a mistake on the exam. Otherwise, make a reasonable assumption and proceed. 5. The questions on the midterm are based on the Chance-It game discussed in class. You will find copies of the java files relating to this game near the end of the exam. API documentation for ArrayList is also provided at the end of this question paper. You may carefully remove these reference pages from the exam (pages 6-12). Question 1 (8 marks) This question relates to the strategies used in method stopRolling() in class Player . The two parts of the question are independent (they do not depend on each other). a) Rewrite stopRolling() to implement the following strategy: A player will roll until he/she gets a roll that is an even number, at least 8, and higher than their opponent’s most recent score. (3 marks) private boolean stopRolling() // ½ mark { return ( ( ( currentRoll % 2 ) == 0 ) && // 1 mark ( currentRoll >= 8 ) && // ½ mark ( currentRoll > opponentsTurnScore ) ); // 1 mark } Note in the first version posted and that given to the TAs for marking, the > in the last line was >=. If you lost marks for this, return your midterm for remarking with that clearly written on the front page.
Background image of page 1

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

View Full DocumentRight Arrow Icon
Page 2 of 12 b) This time our players have decided to go with a simple strategy: Roll 3 times. While this is simple to write, it is a little trickier to program, as the number of rolls is not currently tracked, and this strategy will require changes in method takeTurn() as well as in stopRolling() . Make the changes required in takeTurn() (by crossing out and/or adding to what’s given here), and then rewrite stopRolling() below to implement this new strategy. (5 marks) public int takeTurn(int otherTurnScore) { opponentsTurnScore = otherTurnScore; currentRoll = pairOfDice.roll(); firstRoll = currentRoll; turnScore = currentRoll; int numTurns = 1; System.out.println("\t\tFirst roll: " + firstRoll); for(;;) { if (stopRolling( numTurns )) { totalScore = totalScore + turnScore; System.out.println("\t\tStopping with turn score = " + turnScore + ", total score = " + totalScore); return turnScore; } currentRoll = pairOfDice.roll(); numTurns++; System.out.println("\t\tNext roll: " + currentRoll); if (currentRoll == firstRoll) { turnScore = 0; System.out.println("\t\tOops! Rolled a match!"); System.out.println("\t\tStopping with turn score = " + turnScore + ", total score = " + totalScore); return turnScore;
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 12

SYSC 2004 Midterm Fall 2007 - Carleton University...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online