Answered step by step
Verified Expert Solution
Question
1 Approved Answer
These programs should demonstrate random numbers and overloaded methods. Let s create a simple video game for children. It will be a version of red
These programs should demonstrate random numbers and overloaded methods.
Lets create a simple video game for children. It will be a version of red light green light you may have played as a kid.
The overall premise for this type of would be simple. One person is the stop light and when they say green light everyone can move, and when they say red light everyone has to stop. People moving during red light would have to go back to start.
We are not going to handle people getting sent back to start if they move in a red light in our program because that would make it too big for our assignment. For our game, they DO move at different numbers of steps each move before they win though because they are watching for the light change. The game we will code is to find out who wins.
Program Random Numbers
Make a method called PlayGame that takes four variables: playername, playermaxsteps, playername, playermaxsteps as parameters. This method should make a total for player and a total for player It should then have a loop that goes until the total for player or the total for player is over to cross a finish line. Inside the loop it should find a random number between and playermaxsteps and add it to that players total, and find a random number between and playermaxsteps and add it to that players total. After the loop is over it should use an IF to check who has the most steps and display that persons name as the winner.
So this method is having them walk random number of steps until they cross a finish line, then whoever is farther is the winner, even if they both crossed on the same turn
In main ask the user for the first players name and how many steps that person might make in a turn how fast or risky they will to be and ask the user for the second players name and how many steps that person might make in a turn how fast or risky they will to be Then call the PlayGame and pass it the four variables and see who wins.
Program Overloaded Methods
Take the program above and modify it to handle another choice by the user.
Copy the PlayGame method and add a fifth parameter for the number of steps to cross the finish line. Change the loop to count up to this variable instead of the regular the original version is still using.
Making an overloaded method. You should have versions of PlayGame now
Change main right before it calls the PlayGame method and ask the user of they want to play a regular step game, or a different number of steps. Use an IF to call the first PlayGame if they said they want to play a regular game, and for the variable distance choice ask them how many steps it will be and call the new version of PlayGame and pass the number they give as the fifth variable.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started