Answered step by step
Verified Expert Solution
Link Copied!

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 1 Random Numbers
Make a method called PlayGame() that takes four variables: player1name, player1maxsteps, player2name, player2maxsteps as parameters. This method should make a total for player 1 and a total for player 2. It should then have a loop that goes until the total for player 1 or the total for player 2 is over 30 to cross a finish line. Inside the loop it should find a random number between 1 and player1maxsteps and add it to that players total, and find a random number between 1 and player2maxsteps 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 2 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 30 the original version is still using.
[Making an overloaded method. You should have 2 versions of PlayGame() now]
Change main() right before it calls the PlayGame() method and ask the user of they want to play a regular 30 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

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

Database Security

Authors: Alfred Basta, Melissa Zgola

1st Edition

1435453905, 978-1435453906

Students also viewed these Databases questions

Question

Complete the identity. sec 2 x - tan 2 x =

Answered: 1 week ago

Question

Question What is a Roth 403 (b) plan?

Answered: 1 week ago