Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hello, I’m doing a multi-dimensional array assignment, with with the following r

ID: 3881512 • Letter: H

Question

Hello, I’m doing a multi-dimensional array assignment, with with the following requirements

----------------------------------------------------------.

Background:   

You have been asked to create a program to score a bowling game. Arrays are to be used. The program should use prompts as specified in these requirements.   System.in and System.out should be used (not gui JOptionPane). An object oriented solution should be attempted.

Requirement 1:

Using a one dimensional String array. When the program starts is should prompt the user for the names of the players. It should store the names in a one dimensional array. There can be at most four players (should be stored in a constant). The prompt should be: “Enter player#1 name:” and then repeat with the correct player number until all four are entered.

Requirement 2:

Using a two dimensional int array. Once the user has entered the four player names it should then start prompting for scores for the players. There are 10 ends in a bowling game (should be stored in a constant). The program should use the players name from requirement 1 to prompt for the next score (Text should read: Enter score for John:). The program should loop through each player for end 1, then end 2, continuing until end 10. To be clear, the scores for all four players should be entered for end 1 before starting to prompt for end 2.

Requirement 3:

After each player score is entered, the program should provide a summary of the current scores. This should be accomplished by passing the array to a method and have the method display the results. This should precede the prompt for the next score. (note: if the array and the functionality is in the same class (by your design), you do not have to pass the array to the method).

Requirement 4:

At the end of the scores (ie after all 40 scores are entered), the program should show all of the final scores and add an extra line declaring the winner. The winner declaration should state: “Congratulations John” (if John was the winner).

Sample i/o to be used when getting scored from user:

Current Score

Joe         5 12 15                          | 32

Steve     8 17                                 | 25

Bob       15 12                               | 27

Brian      11 12                               | 23

Enter score for Steve -->

----------------------------------------------------------

I believe I have Requiremnts 1 & 2 done properly, but I’m not eactly sure how to get the required output, and using 2 classes. Below is my current code, any help would be appreciated.

public class Bowler {

    public static void main(String[] args) {

        String[] names;

        int[][] scores;

        int NUM_ENDS = 10;

        int NUM_PLAYERS = 4;

        Scanner input = new Scanner(System.in);

        names = new String[NUM_PLAYERS];

        scores = new int[NUM_PLAYERS][NUM_ENDS];

        for (int i = 0; i < NUM_PLAYERS; i++) {

            System.out.println("Enter player# " + i + " name");

            names[i] = input.nextLine();

        }

        for (int p = 0; p < NUM_ENDS; p++) {

            for (int i = 0; i < NUM_PLAYERS; i++) {

                System.out.println("Enter Game " + p + " Score for " + names[i]);

                scores[i][p] = input.nextInt();

            }

        }

    }

Explanation / Answer

/**

* The java class Bowler that prompts user to

* enter names of the players and scores for

* each player upto 40 scores then print the

* total sum of the each player and then finds

* name of the highest score player and

* print to console*/

//Bowler.java

import java.util.Scanner;

public class Bowler

{

public static void main(String[] args)

{

String[] names;

int[][] scores;

int NUM_ENDS = 10;

int NUM_PLAYERS = 4;

Scanner input = new Scanner(System.in);

names = new String[NUM_PLAYERS];

scores = new int[NUM_PLAYERS][NUM_ENDS];

//create an array of type integer

//to store final scores

int[] finalscores=new int[NUM_ENDS];

int total=0;

for (int i = 0; i < NUM_PLAYERS; i++)

{

System.out.println("Enter player# " + i + " name");

names[i] = input.nextLine();

}

for (int p = 0; p < NUM_ENDS; p++)

{

for (int i = 0; i < NUM_PLAYERS; i++)

{

System.out.println("Enter Game "

+ p + " Score for " + names[i]);

scores[i][p] = input.nextInt();

}

}

//print each player scores and total to console

for (int p = 0; p < NUM_PLAYERS; p++)

{

System.out.printf("%-15s",names[p]);

for (int i = 0; i < NUM_ENDS; i++)

{

total+=scores[p][i];

System.out.printf("%-4d",scores[p][i]);

}

finalscores[p]=total;

System.out.printf("|%-5d",total);

total=0;

System.out.println();

}

//assume that the highscore is the starting player

int highScore=finalscores[0];

String nameOfHighscore=names[0];

//find the highest score player name

for (int p = 1; p < NUM_PLAYERS; p++)

{

if(highScore<finalscores[p])

{

highScore=finalscores[p];

nameOfHighscore=names[p];

}

}

//print the name of high score

System.out.printf("Congratulations "+nameOfHighscore);

}

}

-----------------------------------------------------------------------------------------------------------------------------

Sample Output:

Enter player# 0 name
Joe
Enter player# 1 name
time
Enter player# 2 name
mark
Enter player# 3 name
bill
Enter Game 0 Score for Joe
11
Enter Game 0 Score for time
12
Enter Game 0 Score for mark
12
Enter Game 0 Score for bill
13
Enter Game 1 Score for Joe
14
Enter Game 1 Score for time
12
Enter Game 1 Score for mark
12
1Enter Game 1 Score for bill
2
Enter Game 2 Score for Joe
12
Enter Game 2 Score for time
12
1Enter Game 2 Score for mark
2
Enter Game 2 Score for bill
12
Enter Game 3 Score for Joe
12
Enter Game 3 Score for time
1
Enter Game 3 Score for mark
12
Enter Game 3 Score for bill
12
Enter Game 4 Score for Joe
12
Enter Game 4 Score for time
12
Enter Game 4 Score for mark
12
Enter Game 4 Score for bill
23
Enter Game 5 Score for Joe
23
Enter Game 5 Score for time
23
Enter Game 5 Score for mark
23
Enter Game 5 Score for bill
23
Enter Game 6 Score for Joe
32
Enter Game 6 Score for time
32
Enter Game 6 Score for mark
32
Enter Game 6 Score for bill
32
Enter Game 7 Score for Joe
34
Enter Game 7 Score for time
43
Enter Game 7 Score for mark
34
Enter Game 7 Score for bill
34
Enter Game 8 Score for Joe
43
Enter Game 8 Score for time
4
Enter Game 8 Score for mark
34
Enter Game 8 Score for bill
34
Enter Game 9 Score for Joe
32
Enter Game 9 Score for time
23
Enter Game 9 Score for mark
32
Enter Game 9 Score for bill
23
Joe 11 14 12 12 12 23 32 34 43 32 |225  
time 12 12 12 1 12 23 32 43 4 23 |174  
mark 12 12 12 12 12 23 32 34 34 32 |215  
bill 13 12 12 12 23 23 32 34 34 23 |218  
Congratulations Joe

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote