Я пытаюсь создать программу, которая вычисляет средние баллы для боулеров, средний балл команды и самый высокий средний балл в команде.Запись индивидуального среднего и кумулятивного среднего и самого высокого среднего балла
Проблема:
- Я не могу понять, как отобразить все индивидуальный средний игрок в конце без отображения каждый раз в итерации цикла.
- Как настроить код, чтобы я мог рассчитать совокупный средний и самый высокий средний балл?
Ниже приведен код, который я написал до сих пор
import java.util.*;
public class bowlerama2
{
public static void main(String args[])
{
Scanner keyboard=new Scanner(System.in);
int players;// for number of players on the team
int games=0;// for number of games played
int totalGames=0;
System.out.println("Enter the number of players on the bowling team.");
System.out.println("You must enter a number greater than or equal to three");
players=keyboard.nextInt();
//input validation
while (players<3)
{
System.out.println("Invalid entry. You must enter a number greater than or equal to three for the number of players on the team.");
System.out.println("Enter the number of players on the bowling team:");
players=keyboard.nextInt();
}
for(int number=1;number<=players;number++)
{
System.out.println("Enter the number of games bowled by player " + number + ":");
System.out.println("You must enter a number greater than or equal to two.");
games=keyboard.nextInt();
while (games<2)
{
System.out.println("Invalid entry.You must enter a number greater than or equal to two for the number of games played");
System.out.println("Enter the number of games bowled by player " +number+ ":");
games=keyboard.nextInt();
}
totalGames+=games;
receive (number, games, totalGames);
}
}
public static void receive (int number, int games, int totalGames)
{
Scanner keyboard= new Scanner(System.in);
int total=0;//accumulator for individual scores
int score=0;
int average=0;
for (int amount=1;amount<=games;amount++)
{
System.out.println("Enter the score for player " +number+ " in game " + amount + ":");
score=keyboard.nextInt();
//input validation
while(score<0 || score>300)
{
System.out.println("Invalid entry. Score must be greater than or equal to zero and less than or equal to three hundred");
System.out.println("Enter the score for player " + number+ " in game " +amount+ ":");
score=keyboard.nextInt();
}
total+=score;
average=total/amount;
System.out.println("The average score for player " +number+ " is:" + average);
}
}
}
несвязанный: форматирование сломана. – Nishant
@Nishant Исправлено: – marcog