How do I get the average points from each player of both games?
Write a program that stores the name as a String and numbers as int's of 11 players on a team. Your program should display/output the average points scored of each player over the two games.
Nick (34), Joey (33), Ken (24), Ryan (11), Josh (3), Simon (6), Dillon (10), Mike (28), and Cameron (5).
Game 1: 4, 3, 3, 2, 4, 5, 6, 6, 7, 7, 8. Game 2: 8, 4, 3, 3, 5, 5, 7, 8, 8, 9, 5.
import java.util.Scanner;
import java.util.Arrays;
public class BasketballStats {
public static void main(String[] args) {
// TODO Auto-generated method stub
int[] jerseyNumber = {34, 33, 24, 11, 3, 13, 6, 4, 28, 10};
String[] playerName = {"Jim", "Joe", "Ken", "James", "John", "Bud",
"Clark", "Barry", "Jose", "Paul"};
int[] game1 = new int[11];
int[] game2 = new int[11];
for (int i = 0; i < 10; i++)
System.out.printf("Number %d: %s \n" , jerseyNumber[i],
playerName[i]);
}
public void setGame1Score() {
int[] jerseyNumber = {34, 33, 24, 11, 3, 13, 6, 4, 28, 10};
String[] playerName = {"Jim", "Joe", "Ken", "James", "John", "Bud", "Clark",
"Barry", "Jose", "Paul"};
Scanner input = new Scanner (System.in);
for (int i = 0; i < 10; i++) {
System.out.println("For game 1, how many points does he score?");
int game2 = input.nextInt();
}
}
}
Things tend to get very tedious when you handle data attributes in individual arrays. Conceptually, it makes more sense in this scenario to treat a Player as a unique Object to hold their name, number and scores.
You then can instantiate a player with their name, number and how many games they played. You might, however, like to treat the Player class as a single game and have an Object that describes each Game itself; consisting of 10 Players. The Object is lacking getters/setters for the name and number attribute.
Then you can create a single array to hold all data for a game. If you plan on having multiple games, you may want to have an array of scores instead of a single score per Player.
Then when you will need to get the score somehow.