Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Program 1 - Using Java, Make a method called PlayGame() that takes four variables: player1name, player1maxsteps, player2name, player2maxsteps as parameters. This method should make a

Program 1 - Using Java, 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 Using Java, 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

Advances In Spatial Databases 2nd Symposium Ssd 91 Zurich Switzerland August 1991 Proceedings Lncs 525

Authors: Oliver Gunther ,Hans-Jorg Schek

1st Edition

3540544143, 978-3540544142

More Books

Students also viewed these Databases questions