Note AcademyNote Academy

Computer Science · Oct / Nov 2023 · Paper 2 HL · Question 14

Adapt for 2027Static variables, private attributes, accessors/mutators and creating objects are on the course (B3.1), and super is HL inheritance (B3.2), but the open source part (d) is no longer taught.

IBCS

As printed in the paper

The question as text

14. A company that manufactures a children’s card game, Monster Battle, wants to create a software version. Figure 9 shows three sample cards from the game. Figure 9: Three sample cards from Monster Battle NAME: SPLASHY WATER MONSTER TYPE: 25 HEALTH POINTS: HEAL A FRIEND SPECIAL ABILITIES: 1. PUT OUT FIRE 2. SOAK 3. NAME: SQUISHY WATER MONSTER TYPE: 20 HEALTH POINTS: HEAL A FRIEND SPECIAL ABILITIES: 1. PUT OUT FIRE 2. CLEAN 3. NAME: FLAMEY FIRE MONSTER TYPE: 40 HEALTH POINTS: HEAL A FRIEND SPECIAL ABILITIES: 1. HEAT WATER 2. BURN 3. Each monster begins the game with a number of health points, which are stated on the card, and leaves the game when it has no remaining health points. During a battle between two monsters, players take turns to roll the dice. The results determine how much each monster’s attack will reduce the defending monster’s health points. Some initial classes have been created to model this scenario. public class Monster { public static final int ICE_MONSTER_TYPE = 1; public static final int WATER_MONSTER_TYPE = 2; public static final int FIRE_MONSTER_TYPE = 3; public String name = "Unknown"; public int health = 100; public int strength = 10; public int monsterType = 0; public Monster(String name, int health, int monsterType) { this.name = name; this.health = health; this.monsterType = monsterType; } public void attack(Monster defender) { //to be written } (Option D continues on the following page) (Option D, question 14 continued) private static int rollDice() { //returns a random integer between 1 and 12 return new java.util.Random().nextInt(12)+1; } public static void output(String message) { System.out.println(message); } } public class WaterMonster extends Monster { public WaterMonster(String name, int health) { super(name,health, Monster.WATER_MONSTER_TYPE); } } public class FireMonster extends Monster { public FireMonster(String name, int health){ super(name, health, Monster.FIRE_MONSTER_TYPE); } }

Read automatically from the paper; the printed page above is exact.

Show the answer and mark scheme
  • 14(a)[1]

  • 14(b)(i)[2]

  • 14(b)(ii)[2]

  • 14(c)[2]

  • 14(d)[2]

  • 14(e)[2]

Make a free account to save your answers and see your weak topics and ask the AI why a wrong answer is wrong.