7 Replies - 272 Views - Last Post: 17 November 2019 - 05:38 PM Rate Topic: -----

#1 deannas99   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 21-January 19

How to display output after the user enters input?

Posted 16 November 2019 - 05:43 PM

I'm currently working on a program that utilizes arrays and is written in java code. Right now I am having trouble getting the output to display properly.


public class LabJ2_Group4 {
        public static void main(String[] args) {
        final int NUMBER_OF_PLAYERS=3;
        final int NUMBER_OF_GAMES=2;
        int[][] scoreSheet = new int[NUMBER_OF_GAMES][NUMBER_OF_PLAYERS];
        String[] players={"Colin", "Deanna", "Thom"};
        int total=0;
        double average;
        Scanner KeyboardInput = new Scanner(System.in);
        int input;
        int maxScore=300;
        int minScore=0;
        
        //System.out.println(scoreSheet.length);
        for(int game=0;game<scoreSheet.length;game++){
            System.out.println("Please Enter Scores for game " + (game+1) + ":");
            for(int score=0;score<scoreSheet[game].length;score++){
                System.out.println("Enter Scores for " + players[score] + ":");
                input=KeyboardInput.nextInt();
                if(input<maxScore && input>minScore){
                   // total+=scoreSheet[score][game];
                    scoreSheet[game][score]=input;
                                    }else{
                    System.out.println("Your Score must be between 0 and 300, please enter another.");
                    score--;
                }
                
            } 
            
            
        }
        System.out.println(scoreSheet[0][0]);
        //START OUTPUT/PROCESSING HERE
      System.out.println("\nScore output for " + players[0] + ":");
      System.out.println("Game #1: ");
      System.out.println("Game #2: ");
      
      System.out.println("\nScore output for " + players[1] + ":" );
      System.out.println("Game #1: ");
      System.out.println("Game #2: ");
      
      System.out.println("\nScore output for " + players[2] + ":" );
      System.out.println("Game #1: ");
      System.out.println("Game #2: ");
      
    }
    
    
}


This is my current code. The user is prompted to enter the score for player 1 game 1 then player 2 game 1 and player 3 game 1 and then it goes to ask for game two.

What I can't figure out is the output I have at the bottom. I'm trying to figure out how to get each players score to display for each player for each game.

Any ideas?

Is This A Good Question/Topic? 0
  • +

Replies To: How to display output after the user enters input?

#2 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 15357
  • View blog
  • Posts: 61,571
  • Joined: 12-June 08

Re: How to display output after the user enters input?

Posted 16 November 2019 - 05:46 PM

You would need to utilize loops, similar to how you did the entry.
Was This Post Helpful? 0
  • +
  • -

#3 deannas99   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 21-January 19

Re: How to display output after the user enters input?

Posted 17 November 2019 - 07:58 AM

View Postmodi123_1, on 16 November 2019 - 05:46 PM, said:

You would need to utilize loops, similar to how you did the entry.


How would I go about doing that though?
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 15357
  • View blog
  • Posts: 61,571
  • Joined: 12-June 08

Re: How to display output after the user enters input?

Posted 17 November 2019 - 10:37 AM

Look at what you wrote for lines 15 and 17. Notice how one takes care of what row you are on, and the other the column? Use that same logic to reiterate over your array.
Was This Post Helpful? 0
  • +
  • -

#5 deannas99   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 21-January 19

Re: How to display output after the user enters input?

Posted 17 November 2019 - 03:19 PM

View Postmodi123_1, on 17 November 2019 - 10:37 AM, said:

Look at what you wrote for lines 15 and 17. Notice how one takes care of what row you are on, and the other the column? Use that same logic to reiterate over your array.


So I did that but when its done it only displays the first score entered for all six of the outputs
Was This Post Helpful? 0
  • +
  • -

#6 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 15357
  • View blog
  • Posts: 61,571
  • Joined: 12-June 08

Re: How to display output after the user enters input?

Posted 17 November 2019 - 03:44 PM

Where's that attempt at?
Was This Post Helpful? 0
  • +
  • -

#7 deannas99   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 21-January 19

Re: How to display output after the user enters input?

Posted 17 November 2019 - 05:28 PM

View Postmodi123_1, on 17 November 2019 - 03:44 PM, said:

Where's that attempt at?


for (int score=0; score < scoreSheet[score].length; score++) {
System.out.println("Game #1: " + score );
System.out.println("Game #2: " + score);

System.out.println("\nScore output for " + players[1] + ":" );
System.out.println("Game #1: " + score);
System.out.println("Game #2: " + score);

System.out.println("\nScore output for " + players[2] + ":" );
System.out.println("Game #1: " + score);
System.out.println("Game #2: " + score);
Was This Post Helpful? 0
  • +
  • -

#8 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 15357
  • View blog
  • Posts: 61,571
  • Joined: 12-June 08

Re: How to display output after the user enters input?

Posted 17 November 2019 - 05:38 PM

Mkay.. again, let me press what I said above. You would need a loop inside of a loop like you did for input, but in this case adding up the totals for each row.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1