请写java代码。【题目描述】:某公司举行职员足球比赛,编写程序用于记录球员的信息(队名、球员姓名、球员号码)和比赛进球数。实现随着比赛的推进,每进一球循环输入进球的队名、球员号码。最后输出该项足球比赛的球员进球情况和金靴奖得主。
时间: 2023-03-31 11:02:55 浏览: 232
java代码-使用java解决踢足球的过程的源代码
好的,以下是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<>();
String teamName, playerName;
int playerNumber, goals;
while (true) {
System.out.print("请输入进球的队名:");
teamName = input.next();
System.out.print("请输入进球的球员号码:");
playerNumber = input.nextInt();
if (!playerGoals.containsKey(teamName)) {
playerGoals.put(teamName, new HashMap<>());
}
if (!playerGoals.get(teamName).containsKey(playerNumber)) {
playerGoals.get(teamName).put(playerNumber, );
}
goals = playerGoals.get(teamName).get(playerNumber) + 1;
playerGoals.get(teamName).put(playerNumber, goals);
System.out.println(teamName + "队" + playerNumber + "号球员进了一球!");
System.out.print("是否继续输入进球信息?(Y/N)");
String choice = input.next();
if (choice.equalsIgnoreCase("N")) {
break;
}
}
System.out.println("比赛结束,各队球员进球情况如下:");
for (String team : playerGoals.keySet()) {
System.out.println(team + "队:");
int maxGoals = ;
String bestPlayer = "";
for (int number : playerGoals.get(team).keySet()) {
int playerGoals = playerGoals.get(team).get(number);
System.out.println(number + "号球员:" + playerGoals + "个进球");
if (playerGoals > maxGoals) {
maxGoals = playerGoals;
bestPlayer = team + "队" + number + "号球员";
}
}
System.out.println("金靴奖得主:" + bestPlayer);
}
}
}
阅读全文