Q:

java - establishing new variables based on input

So, the program calls for a bowling game. Once you ask how many players, every player gets 2 throws to knock down 10 pins (simulated by random numbers). If you knock them all down with the first go, then you get 20 points, if on your second go you get 15 points, other than that score = throw 1 + throw 2.
The tricky part for me has been getting each player to alternate frames (2 throws = 1 frame, up to ten frames per player) while the program keeps track of everyone's score! I thought I had it with this but the randoms just add up ill post the output on the bottom
import java.util.Scanner;

public class Bowling {

    public static void main(String [] args){
        Scanner input = new Scanner (System.in);
        Game aNew = new Game();
        int player;
        int i;
        int j;
        int nPlay;

        System.out.print("How many players are there?: ");
        nPlay = input.nextInt();
            for (j = 1; j<= 10; j++) {
                for (i = 1; i <= nPlay; i++ ){
                     player = i; // i tried player i = new Player() but get error "value
                     aNew.getScore(player); // already used in scope""
                }
            }

Games class:
import java.lang.Math;

    public class Game {
    int score = 0;
    int player;
    int ran1;
    int ran2;

    public Game() {
    }

    public int getScore(int player){
        ran1 = (int) (9 * Math.random());
        ran2 = (int) (((10 - ran1)) * Math.random());

        if (ran1 == 10){
            score += 20;
        } else if (ran1 + ran2 == 10){
            score += 15;
        } else {
            score += ran1 + ran2;
        }   System.out.println("Player " + player + " score is: " + score + "\n");
        System.out.println("ran1: " + ran1 + "  ran2: " + ran2);
        return score;
    }
}

Player class:
public class Player {
   /** this class is not doing anything, however i would like for an object to store a score for every player to keep track if that is possible?*/ 
    int score;

    public Player (){
        int score;
    }
}

Output: (suspicious how every time the last player had the highest or I would have never noticed it didn't work!)
How many players are there?: 2

Player 1 score is: 2

ran1: 1  ran2: 1
Player 2 score is: 11

ran1: 8  ran2: 1
Player 1 score is: 16

ran1: 5  ran2: 0
Player 2 score is: 21

ran1: 4  ran2: 1
Player 1 score is: 29

ran1: 8  ran2: 0
Player 2 score is: 35

ran1: 5  ran2: 1
Player 1 score is: 40

ran1: 3  ran2: 2
Player 2 score is: 47

ran1: 6  ran2: 1
Player 1 score is: 56

ran1: 8  ran2: 1
Player 2 score is: 61

ran1: 5  ran2: 0
Player 1 score is: 68

ran1: 7  ran2: 0
Player 2 score is: 77

ran1: 8  ran2: 1
Player 1 score is: 85

ran1: 4  ran2: 4
Player 2 score is: 90

ran1: 4  ran2: 1
Player 1 score is: 97

ran1: 7  ran2: 0
Player 2 score is: 103

ran1: 3  ran2: 3
Player 1 score is: 107

ran1: 4  ran2: 0
Player 2 score is: 114

ran1: 3  ran2: 4
Player 1 score is: 121

ran1: 7  ran2: 0
Player 2 score is: 125

ran1: 0  ran2: 4

A:

Your Player class is currently doing nothing. Fix this by first making accessors and modifiers for your Player.score variable like this. Maybe even give them a name:
public class Player {
     int score;
     String name;
     public Player(String name) { this.name = name; }
     public void getName() { return this.name; }
     public void setScore(int newScore) { score = newScore; }
     public int getScore() { return score; }

}

now your game class should have a collection type of players like
public class Game {
    List<Player> players = new List<Player>();
    public Game() {
    }
    public void AddPlayer(Player p) {
        players.add(p);
    }
    public Player getPlayer(int index) { return players.get(index); }
    public void playerBowl(Player p) {
        ran1 = (int) (9 * Math.random());
        ran2 = (int) (((10 - ran1)) * Math.random());

        if (ran1 == 10){
            p.setScore(p.getScore() +20);
        } else if (ran1 + ran2 == 10){
            p.setScore(p.getScore() +15);
        } else {
            p.setScore(p.getScore() + ran1 + ran2);
        }   System.out.println("Player " + p.getName() + " score is: " + p.getScore() + "\n");
        System.out.println("ran1: " + ran1 + "  ran2: " + ran2);
    }
}

Ill leave the main for you to figure out :D. Sorry if the syntax is a little off, I wrote it in the edit window :/

