请写java代码。【题目描述】:某公司举行职员足球比赛,编写程序用于记录球员的信息(队名、球员姓名、球员号码)和比赛进球数。实现随着比赛的推进,每进一球循环输入进球的队名、球员号码。最后输出该项足球比赛的球员进球情况和金靴奖得主。
时间: 2023-04-01 11:04:21 浏览: 411
好的,以下是 Java 代码:
import java.util.*;
public class FootballGame {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
Map<String, Map<Integer, Integer>> playerGoals = new HashMap<>();
int maxGoals = ;
String goldenBoot = "";
while (true) {
System.out.print("请输入进球的队名(输入结束):");
String teamName = input.nextLine();
if (teamName.equals("")) {
break;
}
System.out.print("请输入进球的球员号码:");
int playerNumber = input.nextInt();
input.nextLine(); // 读取换行符
Map<Integer, Integer> goals = playerGoals.getOrDefault(teamName, new HashMap<>());
int playerGoals = goals.getOrDefault(playerNumber, ) + 1;
goals.put(playerNumber, playerGoals);
playerGoals.put(teamName, goals);
if (playerGoals > maxGoals) {
maxGoals = playerGoals;
goldenBoot = teamName + " " + playerNumber;
}
}
System.out.println("进球情况:");
for (String teamName : playerGoals.keySet()) {
System.out.println(teamName + ":");
Map<Integer, Integer> goals = playerGoals.get(teamName);
for (int playerNumber : goals.keySet()) {
int playerGoals = goals.get(playerNumber);
System.out.println(" " + playerNumber + "号球员:" + playerGoals + "球");
}
}
System.out.println("金靴奖得主:" + goldenBoot);
}
}
阅读全文