in the image below the Red "X" denotes the horse has fallen
While the Race class is almost complete, it still contains some errors that need attention:
import java.util.concurrent.TimeUnit;
import java.lang.Math;
/**
* A three-horse race, each horse running in its own lane
* for a given distance
*
* @author McFarewell
* @version 1.0
*/
public class Race {
private int raceLength;
private Horse lane1Horse;
private Horse lane2Horse;
private Horse lane3Horse;
public Race(int distance) {
raceLength = distance;
lane1Horse = null;
lane2Horse = null;
lane3Horse = null;
}
public void addHorse(Horse theHorse, int laneNumber) {
if (laneNumber == 1) {
lane1Horse = theHorse;
} else if (laneNumber == 2) {
lane2Horse = theHorse;
} else if (laneNumber == 3) {
lane3Horse = theHorse;
} else {
System.out.println("Cannot add horse to lane " + laneNumber + " because there is no such lane");
}
}
public void startRace() {
boolean finished = false;
lane1Horse.goBackToStart();
lane2Horse.goBackToStart();
lane3Horse.goBackToStart();
while (!finished) {
moveHorse(lane1Horse);
moveHorse(lane2Horse);
moveHorse(lane3Horse);
printRace();
if (raceWonBy(lane1Horse) || raceWonBy(lane2Horse) || raceWonBy(lane3Horse)) {
finished = true;
}
try {
TimeUnit.MILLISECONDS.sleep(100);
} catch (Exception e) {}
}
}
private void moveHorse(Horse theHorse) {
if (!theHorse.hasFallen()) {
if (Math.random() < theHorse.getConfidence()) {
theHorse.moveForward();
}
if (Math.random() < (0.1 * theHorse.getConfidence() * theHorse.getConfidence())) {
theHorse.fall();
}
}
}
private boolean raceWonBy(Horse theHorse) {
return theHorse.getDistanceTravelled() == raceLength;
}
private void printRace() {
System.out.print('\u000C');
multiplePrint('=', raceLength + 3);
System.out.println();
printLane(lane1Horse);
System.out.println();
printLane(lane2Horse);
System.out.println();
printLane(lane3Horse);
System.out.println();
multiplePrint('=', raceLength + 3);
System.out.println();
}
private void printLane(Horse theHorse) {
int spacesBefore = theHorse.getDistanceTravelled();
int spacesAfter = raceLength - spacesBefore;
System.out.print('|');
multiplePrint(' ', spacesBefore);
if (theHorse.hasFallen()) {
System.out.print('\u2322');
} else {
System.out.print(theHorse.getSymbol());
}
multiplePrint(' ', spacesAfter);
System.out.print('|');
}
private void multiplePrint(char aChar, int times) {
for (int i = 0; i < times; i++) {
System.out.print(aChar);
}
}
}
Step by stepSolved in 2 steps
- value, which should then be output to the Fahrenheit field. • The second button should perform the inverse function. Be sure to use the field names provided in the comments in your starter code. An example of the program is shown below: Celsius 0.0 >>>> Temperature Converter Fahrenheit 32.0 <<<<arrow_forwardGUI-based program that allows the user to convert temperature values between degrees Fahrenheit and degrees Celsius. The interface should have labeled entry fields for these two values. These components should be arranged in a grid where the labels occupy the first row and the corresponding fields occupy the second row. At start-up, the Fahrenheit field should contain 32.0, and the Celsius field should contain 0.0. The third row in the window contains two command buttons, labeled >>>> and <<<<. When the user presses the first button, the program should use the data in the Fahrenheit field to compute the Celsius value, which should then be output to the Celsius field. The second button should perform the inverse function.arrow_forwardIf you inadvertently create a Click() method for a control that should not generate a click event, you can successfully eliminate the method by ______________. a. deleting the method code from the Form1.cs file b. eliminating the method from the Events list in the Properties window c. adding the method to the Discard window d. making the method a comment by placing two forward slashes at the start of each linearrow_forward
- Create an application that calculates and displays the amount of a homeowners property tax. The tax is 1.35% of the propertys assessed value, which will be entered by the user. a. Prepare a Planning Chart for the application. b. Draw a sketch of an appropriate interface. Be sure to follow the GUI design guidelines covered in the chapter. The guidelines are summarized in Figure 2-20. (If you want to include an image in the interface, you can either use your own image file or download an image file from openclipart.org. When downloading from openclipart.org, be sure to use the SMALL IMAGE (.PNG) button.) c. Create a Windows Forms application. Use the following names for the project and solution, respectively: Tax Project and Tax Solution. Save the application in the VB2017\Chap02 folder. Change the appropriate properties of the form. Also, be sure to verify the name of the startup form. d. Use your Planning Chart as a guide when building the interface. e. Code the Exit button. (You do not need to code the button that calculates and displays the tax.) Save the solution and then start the application. Test the access keys, tab order, and Exit button and then close the solution.arrow_forwardJavaFXarrow_forwardWhen the page loads, the main menu appears, where the following parameters must be set to start the game: Name (player's name) Map difficulty (Easy, Hard) Only after this can the game be started. From the menu you should also be able to open the game description. A leaderboard can also appear, showing who completed the map the fastest. Note! The game will have multiple "pages": the menu, the game, and possibly the description. However, these should not be in separate HTML files but should be handled within a single HTML file. You can achieve this with divs that are shown/hidden using JavaScript. The game description can also appear in a pop-up window.arrow_forward
- GUI calculator in python - The user enters two integers into the text fields. - When the Add button is pressed, the sum of values in the text fields are shown after the Equals: as a label. - The Clear button clears the values in the text fields and the result of the previous calculation. The cleared values can be blank or zero. - The Quit button closes the GUI window.arrow_forwardPicture card: Create a picture card that looks SIMILAR to this. There are images available in the "images" directory to assist you in making this card. They are not the same images, but there is an image of a desert and a person. Picture card In this screenshot, the title is "Title goes here", the secondary text is "Secondary text", and the body text is "Greyhound divisively hello coldly wonderfully marginally far upon excluding." The card's root element is a with a class of "card". The card is 344px wide. The desert picture is 194px tall. The padding between the body text and everything else is 16px. The color of the title text is #000. The color of the secondary and body texts is #232F34. The size of the person picture is 40px in diameter. The size of the body text is 11px. The size of the title is 22px. For the padding or margin around any other elements, use your best judgment to make it look like the screenshot.arrow_forward2. Image ViewerWrite an application that allows the user to view image files. The application should useeither a button or a menu item that displays a file chooser. When the user selects an imagefile, it should be loaded and displayed.arrow_forward
- JAVA Create a GUI application where the user enters the whole cost of an item and its markup percentage into text fields. (for example, if an item's wholesale cost is $5 and its markup percentage is 100%, then its retail price is $10.) The application should have a button that displays the item's retail price when clicked.Example of it running in the image providedarrow_forwardProgramming Exercise #2: Grade Create an application that calculates and displays the percentage of students receiving a grade of P (for Passed) and the percentage of students receiving a grade of F (for Failed). Before creating your Planning Chart, consider what information the user will need to enter (if Grade >= 75, PASSED, FAILED). a. Prepare a Planning Chart for the application. b. Draw a sketch of an appropriate interface. Be sure to follow the GUI design guidelines covered in the chapter. The guidelines are summarized in Figure 2-20 (found on page 66). (If you want to include an image in the interface, you can either use your own image file or download an image file from openclipart.org. When downloading from openclipart.org, be sure to use the SMALL IMAGE (.PNG) button.) c. Create a Windows Forms application. Use the following names for the project and solution, respectively: FamilyName_Grade Project and FamiltyName_Grade Solution. Save the application in the…arrow_forwardDesign and implement an application that presents three buttons and a label to the user. The buttons should be labeled Increment, Decrement, and Randomize. Display a numeric value (initially 50) using the label. Each time the Increment button is pushed, increment the value displayed. Likewise, each time the Decrement button is pushed, decrement the value displayed. When the Randomize button is pushed, the number displayed should be randomized between 1 and 100, inclusive.arrow_forward
- Programming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage LearningMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT