Write a Java program segment (not an entire program) that will summarize the season results for 5 players on one of TRU’s basketball teams. Each player played 10 games.
Your program segment should ask the user for a player’s name, followed by the points that player scored in each of the 10 games (a total of 11 pieces of input). Your program will then produce the summary line shown below for that player.
Your program should get the data for each of the remaining 4 players and produce a summary line for those as well.
Your program should produce the summary in the format shown below, for each player. ( not the actual data, for illustration purposes only)
NOTES: PPG = average points per game (format to one decimal place)
High = highest points in one of the 10 games
Low = lowest points in one of the 10 games
( you may assume the highest and lowest points occurred only once
each)
This is the summary you will produce, including the 2 lines at the end:
Player PPG High Low
Name 1 20.1 29 11
repeat the same summary for each of the remaining 4 players
Name 3 had the highest one game result of 31 points in game #7
Name 2 had the lowest one game result of 5 points in game #5.
/*JAVA segment code is written and explained below from main method */
public static void main(String[] args) {
/*Here is the code java codde
segment that
* you need to have inside main
function of
* any java class, that is
* "public static void main(String[]
args) { } *****************/
int number_of_players=5;
/*Now we will tell make a array for
storing summary of each player */
int player_score[][]=new
int[5][10];
String player_name[]=new
String[5];
Double ppg=10.0;
Double PPG=0.0;
/*Below we need to use Scanner
object ,
* which is used for taking input
from user in java language*/
Scanner sc=new
Scanner(System.in);
for(int
i=0;i<number_of_players;i++)
{
int sum=0;
System.out.println("Enter Player's Name for player number:
"+(i+1));
player_name[i]=sc.next();
System.out.println("Now please enter the scores of player "+ (i+1)+
" till 10th match");
for(int
j=0;j<10;j++)
{
player_score[i][j]=sc.nextInt();
sum+=player_score[i][j];/*This sum will help in calculaing average
that is PPG*/
}/*Closing Inner
for loop*/
/*calculating
PPG as shown below is for getting
* average, as
PPG is average, we will divide it
* by 10 as there
are 10 matches only */
/***************IMPORTANT**********
* Here we used
"Math.round which on
* multiplying
and dividing by ten "10" will
* give us answer
up to one decimal place.
* If we use
hundred "100" , we will get
* answer rounded
off up to 2 decimal places and so on "*/
PPG=
Math.round((sum/ppg) * 10.0) / 10.0;
/*Code for
calculating maximum of the player score*/
int max=0;
for(int
j=0;j<10;j++)
{
if(max<player_score[i][j])
{
max=player_score[i][j];
}
}
/*Code for
calculating minimum of the player score*/
int
min=Integer.MAX_VALUE;
for(int
j=0;j<10;j++)
{
if(min>player_score[i][j])
{
min=player_score[i][j];
}
}
System.out.println("Summary of Player "+(i+1)+" is ");
/******************PRINTING SUMMARY*****************/
System.out.println("PLAYER PPG High LOW");
System.out.println(player_name[i]+" "+PPG+" "+max+" "+min);
System.out.println();
}/*Closing outer for loop*/
}/*Closing main method*/
Get Answers For Free
Most questions answered within 1 hours.