Question: Java help! Thank you in advance! Here's the code i have so far with an expected OUTPUT in the instructions below: CODE: import java.util.Random; public

Java help! Thank you in advance! Here's the code i have so far with an expected OUTPUT in the instructions below:

CODE:

import java.util.Random;

public class BatterUp3 {

public static String[] name = {"Tristan","Zoe","Frank","Chuck","Erin","Sam","Gigi","Horace","Zeke"};

public static void main(String []args) {

int outCount = 0;

for( ) { //this should loop until all 9 players have struck out

}

batterTakeTurn();

}

public static boolean batterTakeTurn() {

int strikeCount = 0;

int ballCount = 0;

int returnVal;

boolean isOut = true;

while(true) {

returnVal = bat();

if(returnVal == -1)

strikeCount++;

if(strikeCount == 3) {

System.out.println("Strike out!");

break;

}

if(returnVal == -2)

ballCount++;

if(ballCount == 4) {

System.out.println("Walk!");

break;

}

if (returnVal > 0){

break;

}

}

return isOut;

}

public static int bat() {

Random random = new Random();

int dice1 = random.nextInt(100);

int dice2 = random.nextInt(100);

dice1 %= 6;

dice2 %= 6;

dice1++;

dice2++;

System.out.print("Rolled " + dice1 + " " + dice2 + " ");

if(dice1 == dice2) {

switch (dice1) {

case 1:

System.out.println("Single!");

return 1;

case 2:

System.out.println("Double!");

return 2;

case 3:

System.out.println("Triple!");

return 3;

case 4:

System.out.println("Home Run!");

return 4;

}

}

int sum = dice1 + dice2;

if(sum % 2 == 0) {

System.out.println("Strike!");

return -1;

} else {

System.out.println("Ball!");

return -2;

}

}

INSTRUCTIONS:

BatterUp3 Add a static String array in the class to contain nine player names. Pick any nine names to populate the player names. Add a return type of boolean (e.g. isOut) to batterTakeTurn, which returns true if the player's turn is over due to a strike out; otherwise, it returns false. In main, use this returned boolean value to increment the outs counter and the next player is up. Continue to loop through the batting order repeatedly (starting over at the beginning of the array after the last batter). When three outs have occurred, break out of that loop and end. Change the main method to loop through all nine players continuously until three outs have occurred. In this game, the only way to get an out is by striking out. Additional changes to the main method: - Declare an int variable to count the outs. Initialize to 0 - Loop through the players array, for each player - Print out the name of player at bat along with the total outs - Change that player's location from -1 (dugout) to 0 (at bat) - Player continues to bat until the batterTakeTurn method returns true (Strike out) - Wrap that for loop for all players in a while loop that continues until 3 outs - if all batters have batted without three outs, the while loop will cause the batting order to repeat until three outs have occurred BatterUp3 SAMPLE OUTPUT: > java BatterUp3 Amy is at bat with 0 outs Rolled 4 2 STRIKE! Rolled 3 5 STRIKE! Rolled 2 6 STRIKE! Strike out!! Bob is at bat with 1 outs Rolled 3 3 Triple! Carl is at bat with 1 outs Rolled 5 4 BALL! Rolled 5 3 STRIKE! Rolled 4 1 BALL! Rolled 3 2 BALL! Rolled 6 5 BALL! Walk Diana is at bat with 1 outs Rolled 1 1 Single! Ed is at bat with 1 outs Rolled 5 5 STRIKE! Rolled 1 4 BALL! Rolled 3 6 BALL! Rolled 3 2 BALL! Rolled 5 5 STRIKE! Rolled 6 6 STRIKE! Strike out!! Francis is at bat with 2 outs Rolled 4 1 BALL! Rolled 6 6 STRIKE! Rolled 3 1 STRIKE! Rolled 4 1 BALL! Rolled 1 3 STRIKE! Strike out!! 3 outs - next team!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!