The application must contain at least these five separate methods. Name them whatever you like.
This is functionality they will perform in the application: main method, random number generator method , Initial application display and user input method, Display race information, Display ending information and user continue input.
Use the random() method of the java.lang.Math class to generate a random number.
The user will enter a response to the initial prompt. The application will generate a random number for a witch and display the race information.
The witch whose location is equal to or higher than the user’s initial input value and all the other witches is the winner who has reached the top of the mountain first.
Once a witch has reached the top of the mountain the ending information and user continue input prompt will be displayed.
When the user responds to the “Play Again?” prompt, the application should only accept a value of “yes” or “no”. If the user enters invalid data, the application should display an appropriate error message and prompt the user again until the user enters valid data.
Example:
Enter how many spaces it is to the top:
20
Start the game with these witches
Xtra Bad Wich
Supra Wit
Mountain Manwitch
On your mark get set go
Xtra Bad Wich moves 3 spaces and is at location 3
Supra Wit moves 1 spaces and is at location 1
Mountain Manwitch moves 7 spaces and is at location 7
They are off and flying with Mountain Manwitch in the lead
Xtra Bad Wich moves 5 spaces and is at location 8
Supra Wit moves 9 spaces and is at location 10
Mountain Manwitch moves 2 spaces and is at location 9
They are off and flying with Supra Wit in the lead
Xtra Bad Wich moves 10 spaces and is at location 18
Supra Wit moves 9 spaces and is at location 19
Mountain Manwitch moves 7 spaces and is at location 16
They are off and flying with Supra Wit in the lead
Xtra Bad Wich moves 8 spaces and is at location 26
Supra Wit moves 3 spaces and is at location 22
Mountain Manwitch moves 1 spaces and is at location 17
Xtra Bad Wich wins the race!!!
Play again? (yes/no): y
Error! Entry must be 'yes' or 'no'. Try again.
Play again? (yes/no): no
##################### Witch.java #######################
/**
* The Class Witch.
*/
public class Witch {
/** The name. */
private String name;
/** The location. */
private int location;
/** The moves. */
private int moves;
public Witch(String name, int location, int moves)
{
this.name = name;
this.location = location;
this.moves = moves;
}
/**
* Gets the name.
*
* @return the name
*/
public String getName() {
return name;
}
/**
* Sets the name.
*
* @param name
* the new name
*/
public void setName(String name) {
this.name = name;
}
/**
* Gets the location.
*
* @return the location
*/
public int getLocation() {
return location;
}
/**
* Sets the location.
*
* @param location
* the new location
*/
public void setLocation(int location) {
this.location = location;
}
public void updateLocation(int location) {
this.location += location;
}
/**
* Gets the moves.
*
* @return the moves
*/
public int getMoves() {
return moves;
}
/**
* Sets the moves.
*
* @param moves
* the new moves
*/
public void setMoves(int moves) {
this.moves = moves;
}
@Override
public String toString() {
return String.format("%s moves %d
spaces and is at location %d", name, moves, location);
}
}
####################### GameSimulator.java
#########################
package solution5;
import java.util.Scanner;
/**
* The Class GameSimulator.
*/
public class GameSimulator {
/**
* The main method.
*
* @param args
* the arguments
*/
public static void main(String[] args) {
Witch xtraBadWitch = new
Witch("Xtra Bad Wich", 0, 0);
Witch supraWit = new Witch("Supra
Wit", 0, 0);
Witch mountainManWitch = new
Witch("Mountain Manwitch", 0, 0);
Scanner scan = new
Scanner(System.in);
int noOfSpaces = initialInput(scan,
xtraBadWitch, supraWit, mountainManWitch);
boolean stop = false;
do {
// till number of spaces, all witch
needs to moves.
playGame(scan,
noOfSpaces, xtraBadWitch);
playGame(scan,
noOfSpaces, supraWit);
playGame(scan,
noOfSpaces, mountainManWitch);
// checking the
winner
if
(xtraBadWitch.getLocation() >= noOfSpaces ||
supraWit.getLocation() >= noOfSpaces
||
mountainManWitch.getLocation() >= noOfSpaces) {
if (xtraBadWitch.getLocation() >
supraWit.getLocation()
&&
xtraBadWitch.getLocation() > mountainManWitch.getLocation())
{
if (displayFinalResult(scan,
xtraBadWitch)) {
resetInput(scan, noOfSpaces, xtraBadWitch, supraWit,
mountainManWitch);
} else {
stop =
true;
}
} else if (supraWit.getLocation() >
xtraBadWitch.getLocation()
&&
supraWit.getLocation() > mountainManWitch.getLocation()) {
if (displayFinalResult(scan,
supraWit)) {
resetInput(scan, noOfSpaces, xtraBadWitch, supraWit,
mountainManWitch);
} else {
stop =
true;
}
} else if (mountainManWitch.getLocation() >
xtraBadWitch.getLocation()
&&
mountainManWitch.getLocation() > supraWit.getLocation()) {
if (displayFinalResult(scan,
mountainManWitch)) {
resetInput(scan, noOfSpaces, xtraBadWitch, supraWit,
mountainManWitch);
} else {
stop =
true;
}
}
}
} while (!stop);
}
/**
* Reset input.
*
* @param scan
* the scan
* @param noOfSpaces
* the no of spaces
* @param xtraBadWitch
* the xtra bad witch
* @param supraWit
* the supra wit
* @param mountainManWitch
* the mountain man witch
*/
private static void resetInput(Scanner scan, int
noOfSpaces, Witch xtraBadWitch, Witch supraWit,
Witch
mountainManWitch) {
xtraBadWitch.setMoves(0);
xtraBadWitch.setLocation(0);
supraWit.setLocation(0);
supraWit.setMoves(0);
mountainManWitch.setMoves(0);
mountainManWitch.setLocation(0);
noOfSpaces = initialInput(scan,
xtraBadWitch, supraWit, mountainManWitch);
}
/**
* Play game.
*
* @param scan
* the scan
* @param noOfSpaces
* the no of spaces
* @param witch
* the witch
*/
private static void playGame(Scanner scan, int
noOfSpaces, Witch witch) {
int moves =
generateMoves(noOfSpaces);
witch.setMoves(moves);
witch.updateLocation(moves);
displayGameProgress(witch);
}
/**
* Generate moves.
*
* @param limit
* the limit
* @return the int
*/
private static int generateMoves(int limit) {
return (int) (Math.random() * limit
- 1);
}
/**
* Initial input.
*
* @param scan
* the scan
* @param xtraBadWitch
* the xtra bad witch
* @param supraWit
* the supra wit
* @param mountainManWitch
* the mountain man witch
* @return the int
*/
private static int initialInput(Scanner scan, Witch
xtraBadWitch, Witch supraWit, Witch mountainManWitch) {
System.out.println("Enter how many
spaces it is to the top:");
int input = scan.nextInt();
System.out.println("Start the game
with these witches");
System.out.println(xtraBadWitch.getName());
System.out.println(supraWit.getName());
System.out.println(mountainManWitch.getName());
System.out.println("On your mark
get set go");
return input;
}
/**
* Display game progress.
*
* @param witch
* the witch
*/
private static void displayGameProgress(Witch witch)
{
System.out.println(witch.toString());
}
/**
* Display final result.
*
* @param scan
* the scan
* @param witch
* the witch
* @return true, if successful
*/
private static boolean displayFinalResult(Scanner
scan, Witch witch) {
System.out.println(witch.getName()
+ " wins the race!!!");
boolean tryAgain = true;
do {
System.out.println("Play again? (yes/no):");
String option =
scan.next();
switch
(option.toLowerCase()) {
case
"yes":
return true;
case "no":
return false;
default:
System.err.println("Error! Entry must be 'yes'
or 'no'. Try again.");
}
} while (tryAgain);
return tryAgain;
}
}
################ Sample output ######################
The application must contain at least these five separate methods. Name them whatever you like. This...
INTRODUCTION: Play sorry with two die, and one peg. Move your piece down the board first. But rolling certain numbers will change the pace of the game. INCLUDE IN YOUR ASSIGNMENT: Annotation is a major part of any program. At the top of each of your C++ programs, you should have at least four lines of documentation: // Program name: tictactoe.cpp // Author: Twilight Sparkle // Date last updated: 5/26/2016 // Purpose: Play the game of Tic-Tac-Toe ASSIGNMENT: Sorry Game...
Requirements: 1. You are not allowed to use global variables. 2. Must declare the following two constants public static final int POINTS = 30; public static final int FORFEIT_POINTS = 20; 3. You can implement your own solution but you are required to break down the problem into smaller pieces. 4. You must provide the output for two rounds of game minimum. 5. Since we are using the Random number generator your output will not be exactly like mine. However,...