Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem Specification Write an application which simulates a race between different types of creatures. Your output should show a print out of the final configuration

Problem Specification Write an application which simulates a race between different types of creatures. Your output should show a print out of the final configuration of the race (when at least one creature has won the race). Your classes will need to contain all the logic for moving the racers, including keeping track of each of their positions along the track.

Racetrack The racetrack will consist of different types of terrain open plains, forests, lakes, and deserts. The track will be represented by a one-dimensional array of characters, randomly generated, where different characters represent different terrain. On each turn, each racer (before they move) will get a random number of movement points to move through the terrain. The random number should be an integer in the range from 1 to the creatures maximum speed inclusive. When the creature reaches the finish line it becomes a winner and stops moving (note: it is possible for more than one creature to reach the finish line during the same turn they are all winners). The different types of terrain and how they will be represented in your program are shown below: . = open plains # = forest O = lake ~ = desert | = finish line

Creature Types The racers will consist of 3 different types of creatures. Each creature type will move through the terrain in different ways e.g. in a forest, an ostrich may be hindered while a monkey moves especially well. A creature must have enough movement points remaining to enter the next terrain block or it cannot do so. Monkey: Has a maximum speed of 4 Can move into forests for free (costs 0 movement points) Monkeys dont like to get hot, so moving into desert costs 2 movement points If a monkey moves into a lake, it stops to play, reducing its remaining movement points to 0 Moving into other terrain costs 1 movement point

Ostrich: Has a maximum speed of 5 If an ostrich starts its turn in open plains or desert, it gains a bonus of 1 movement point Ostriches get lost easily, so moving into a forest costs 3 movement points Ostriches dont like to get wet, so moving into a lake costs 2 movement points Moving into other terrain costs 1 movement point

Turtle: Has a maximum speed of 2 Can move into lakes for free (costs 0 movement points) Turtles are slow but steady, and can move into all other terrain for 1 movement point

Points to note: At the beginning of the race, the creatures are in the first position (i.e., index zero) on the track which is represented by a one-dimensional array. When it is a creatures turn to move, it can keep moving along the track as long as it has enough movement points to keep going (so a single turn could mean moving through several types of terrain on the race track). Once a creature enters a terrain, it can keep moving along the track (if the terrain is the same) without losing additional movement points. Once the terrain changes, it can only move if it has enough movement points to enter that terrain (based on the information provided about each creature). If it doesnt have enough movement points to enter the next terrain, it must wait for another turn when it can potentially receive enough movement points to move again.

Design Phase The Design Phase does not explicitly tell you all of the fields and methods you will need to create for the creature classes. Instead, it walks you through determining these for yourselves.

Basic Structure Each creature type can be represented by its own class. Since they are all creatures, it makes sense to share the same Creature superclass. You will only ever want to instantiate objects of the specific creature types (not a Creature type). What does that indicate about the Creature superclass? All creatures will need to have a name and a maximum speed, as well as methods to access this information. Each creature should also have a reference to the racetrack array, in order to know what type of terrain it is moving into, and it should know its position along the track and a flag indicating whether or not it is a winner. Decide what attributes need to be initialized when you instantiate a new creature, and include an appropriate constructor. A creature also needs to be able to move, but each individual subclass will implement this in different ways. Note that each subclass must implement this method how can the superclass be used to enforce this requirement in its subclasses? Each subclass should override superclass method(s) as appropriate.

In addition to the Creature classes, you will need a Race class which controls everything including generating a racetrack, maintaining a list of racers, and making the racers move at each turn. It should also indicate whether or not a racer has crossed the finish line, checking for this at the end of each turn.

Certain methods must be included in the Race class; this will be enforced by having the Race class implement the following interface RaceInterface (provided below): public interface RaceInterface { //Returns a char array representing the racetrack char[] getRacetrack(); //Returns the name of the racer at the given index String getRacerName(int racerIndex); //Returns the position of the racer at the given index int getRacerPosition(int racerIndex); //Returns whether or not the racer at the given index is a winner boolean getRacerIsWinner(int racerIndex); //Creates the racetrack of the given length and instantiates numRacers number of racers void createRace(int length, int numRacers); //Causes each racer to take one turn, moving a number of spaces based on their // movement speed and the terrain void advanceOneTurn(); }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Mastering Real Time Analytics In Big Data A Comprehensive Guide For Everyone

Authors: Lennox Mark

1st Edition

B0CPTC9LY9, 979-8869045706

More Books

Students also viewed these Databases questions