Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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:

image text in transcribed

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.

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

MySQL/PHP Database Applications

Authors: Jay Greenspan, Brad Bulger

1st Edition

978-0764535376

More Books

Students also viewed these Databases questions

Question

Describe the process used in a Chapter 11 bankruptcy.

Answered: 1 week ago

Question

Analyze the impact of labor unions on health care.

Answered: 1 week ago

Question

Assess three motivational theories as they apply to health care.

Answered: 1 week ago

Question

Discuss the history of U.S. labor unions.

Answered: 1 week ago