1. Engineering
  2. Computer Science
  3. create a java program a horse race following all the...

Question: create a java program a horse race following all the...

Question details

Create a Java Program (A horse race) following all the requirements below, make sure to read all tips and hints:

Overview

Use the principles of Object Oriented Design (OOD) and Object Oriented Programming (OOP) to create a JAVA horse race. Each horse will be an object, and the race will be another object that contains a list of horses and manages the race. Along the way, you will experiment with UML, create classes, review access modifiers, build member variables, add access methods, and create constructors. The Project Build a program that simulates a horse race. The race works just like the last assignment, and the user may not ever see the difference. But this time, the underlying design will use objects. You will have two objects in the game. There will be an array of five horse objects. The horse will 'know' how to advance according to a random flip, and to return its position. The other primary entity in this game is the race (or the track, if you prefer.) This object will contain a series of horses. It will also have the ability to start the race. When the race is running, the race class will 'tell' each horse to advance, and will print out a track diagram showing the relative positions of the horses.

Sample Run

You can find an HTML5 version here: http://cs.iupui.edu/~aharris/240/horseRace.html (Links to an external site.)Links to an external site.

Note that you will not need the automation feature nor a GUI.

This just gives you an idea of the race concept.

Here is a sample run of the program: 0........................ .1....................... 2........................ 3........................ .4.......................

Press enter for another turn: 0........................ ..1...................... .2....................... .3....................... .4.......................

Press enter for another turn: .0....................... ..1...................... ..2...................... .3....................... .4.......................

Press enter for another turn: .0....................... ...1..................... ..2...................... ..3...................... ..4......................

Press enter for another turn: ..0...................... ...1..................... ..2...................... ...3..................... ..4......................

Press enter for another turn: ..0...................... ....1.................... ..2...................... ....3.................... ...4.....................

Press enter for another turn: ...0..................... .....1................... ...2..................... .....3................... ....4....................

Press enter for another turn: ...0..................... .....1................... ...2..................... .....3................... .....4...................

Press enter for another turn: ...0..................... ......1.................. ....2.................... ......3.................. .....4...................

Press enter for another turn: ....0.................... .......1................. .....2................... .......3................. .....4...................

Press enter for another turn: .....0................... ........1................ ......2.................. ........3................ .....4...................

Press enter for another turn: ......0.................. ........1................ .......2................. .........3............... ......4..................

Press enter for another turn: .......0................. ........1................ .......2................. .........3............... ......4..................

Press enter for another turn: ........0................ ........1................ .......2................. ..........3.............. ......4..................

Press enter for another turn: .........0............... .........1............... .......2................. ...........3............. ......4..................

Press enter for another turn: .........0............... .........1............... ........2................ ............3............ ......4..................

Press enter for another turn: ..........0.............. .........1............... .........2............... ............3............ ......4..................

Press enter for another turn: ...........0............. ..........1.............. .........2............... .............3........... .......4.................

Press enter for another turn: ............0............ ..........1.............. ..........2.............. ..............3.......... .......4.................

Press enter for another turn: .............0........... ..........1.............. ..........2.............. ...............3......... ........4................

Press enter for another turn: ..............0.......... ...........1............. ..........2.............. ................3........ ........4................

Press enter for another turn: ..............0.......... ............1............ ..........2.............. .................3....... ........4................

Press enter for another turn: ..............0.......... ............1............ ...........2............. ..................3...... .........4...............

Press enter for another turn: ...............0......... .............1........... ...........2............. ...................3..... .........4...............

Press enter for another turn: ................0........ .............1........... ...........2............. ....................3.... ..........4..............

Press enter for another turn: ................0........ .............1........... ............2............ ....................3.... ..........4..............

Press enter for another turn: ................0........ ..............1.......... .............2........... ....................3.... ..........4..............

Press enter for another turn: .................0....... ..............1.......... ..............2.......... .....................3... ...........4.............

Press enter for another turn: .................0....... ..............1.......... ...............2......... ......................3.. ............4............

Press enter for another turn: .................0....... ..............1.......... ...............2......... .......................3. .............4...........

Press enter for another turn: .................0....... ..............1.......... ................2........ .......................3. ..............4..........

Press enter for another turn: .................0....... ..............1.......... ................2........ ........................3 ...............4.........

Press enter for another turn: .................0....... ...............1......... ................2........ ......................... Horse 3 wins! ................4........

Press enter for another turn:

Code Organization

While you have already written this program in a procedural fashion, this program is a perfect candidate for the object-oriented paradigm. Please use the UML diagram I created as a starting point:

Race 5 Horse h: Horse] +length: int +Race() +Race (length:int) +printLane (horseNum:int): voi +start() void position int +Horse() +advance) void +getPosition): int

Programming Methodology

It is not necessary to create a GUI for this project. Since this is an exercise in OOP programming, you are expected to create at least two classes, as indicated in the class diagram provided above. All the methods and member variables necessary are listed in the UML diagram, but you might need to create other local variables inside your methods. There are other legitimate ways to organize this data, but this is one of the simpler techniques. Tips You will need two classes. They can be in the same file or different files. If the two classes are defined in the same file, only one can be public. It should be the one with main(). Each class will need a simple constructor. (My version of Race actually has two constructors.) Remember that every class should have a null parameter constructor. Also, remember that the main point of a constructor is to initialize the member variables. You might additionally do some other initial work that happens only once in the constructor. (That was a hint.) Each method should represent something the class can DO. Each member variable should be information that the data has. This program uses an aggregate data structure. One of the classes includes an array of instances of the other class. The Race class' start() method (at least in my version of the program) controls most of the race action. It not only starts the race, but it controls the entire race. The Race.printLane() method is used to print out a visual depiction of the lane for a particular horse. This method is easy to visualize, but it can be tricky to implement, because the horse ID will probably be an integer, and the rest of the track will likely be characters.

Algorithm

As always, begin with an algorithm in plain text. This document should begin by describing the main purpose of the program using the Goals - Input - Output - Steps technique we've been using. For EACH function/method you have in the program or classes, you must go through the same process (Defining goals, input, output, steps). Remember that your algorithm should be complete enough that by the time you are ready to start writing code, you pretty much know what you are going to do. You should get mostly through the algorithm step together in the recitation center, but definitely try to write this on your own as well. Your algorithm file must be in a .txt file named: algorithm.txt

Black Belt Extensions

The black belt potential for this project is enormous. As always, begin with the basic expectations. Once you get the core program working, there are many ways to extend it. Here are a few options: Create a new type of horse that advances on a percentage rather than a simple coin flip. This could be an extension of the basic Horse class. For the constructor, include an int parameter that indicates the percentage of time the horse will move forward. You will need to modify the advance() method to handle the more elaborate movement mechanism. You may want to then have horses with differing abilities in the same race. Implement a betting mechanism. Allow the user to bet on a race before it begins. Keep track of the user's cash through several runs of the program. Give horses with different abilities different odds. Reward a long shot (40% chance of advancing each round) much more than a favorite (50% chance of advancing.) Multi-player - Allow more than one player to place bets, keeping track of each player's performance Bribery. Allow user to 'purchase' performance modifications. This will increase or decrease a particular horse's performance during a race, but there is a chance the player will be caught and immediately lose all his money. Cosmetic changes. Add a menu system, GUI, or other features to make the game more aesthetically appealing. Try writing the game in another language.

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution