我来为您创建一个Java案例,统计篮球比赛中球员的转身过人次数,这里设计一个简单的篮球比赛统计系统:

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
// 球员类
class Player {
private String name;
private int turnAroundCount; // 转身过人次数
private List<Action> actions;
public Player(String name) {
this.name = name;
this.turnAroundCount = 0;
this.actions = new ArrayList<>();
}
public void addAction(Action action) {
actions.add(action);
if (action.getType() == ActionType.TURN_AROUND) {
turnAroundCount++;
}
}
public int getTurnAroundCount() {
return turnAroundCount;
}
public String getName() {
return name;
}
public List<Action> getActions() {
return actions;
}
}
// 动作类型枚举
enum ActionType {
TURN_AROUND("转身过人"),
DRIBBLE("运球"),
PASS("传球"),
SHOOT("投篮"),
REBOUND("篮板"),
DEFENSE("防守");
private String description;
ActionType(String description) {
this.description = description;
}
public String getDescription() {
return description;
}
}
// 动作类
class Action {
private ActionType type;
private int timestamp; // 时间戳(秒)
private String description;
public Action(ActionType type, int timestamp) {
this.type = type;
this.timestamp = timestamp;
this.description = type.getDescription();
}
public ActionType getType() {
return type;
}
public int getTimestamp() {
return timestamp;
}
@Override
public String toString() {
return String.format("[%d秒] %s", timestamp, description);
}
}
// 比赛统计类
class BasketballGameStats {
private Map<String, Player> players;
private List<Action> gameLog; // 比赛日志
private int gameTime; // 比赛时间(秒)
public BasketballGameStats() {
this.players = new HashMap<>();
this.gameLog = new ArrayList<>();
this.gameTime = 0;
}
// 添加球员
public void addPlayer(String name) {
if (!players.containsKey(name)) {
players.put(name, new Player(name));
}
}
// 记录动作
public void recordAction(String playerName, ActionType actionType, int timestamp) {
Player player = players.get(playerName);
if (player == null) {
addPlayer(playerName);
player = players.get(playerName);
}
Action action = new Action(actionType, timestamp);
player.addAction(action);
gameLog.add(action);
gameTime = Math.max(gameTime, timestamp);
}
// 获取转身过人次数最多的球员
public Player getTopTurnAroundPlayer() {
Player topPlayer = null;
int maxCount = 0;
for (Player player : players.values()) {
if (player.getTurnAroundCount() > maxCount) {
maxCount = player.getTurnAroundCount();
topPlayer = player;
}
}
return topPlayer;
}
// 获取所有球员的转身次数排名
public List<Player> getRanking() {
List<Player> rankedPlayers = new ArrayList<>(players.values());
rankedPlayers.sort((p1, p2) ->
Integer.compare(p2.getTurnAroundCount(), p1.getTurnAroundCount()));
return rankedPlayers;
}
// 打印比赛统计摘要
public void printSummary() {
System.out.println("========== 比赛统计摘要 ==========");
System.out.println("比赛时间: " + gameTime + "秒");
System.out.println("参与球员数: " + players.size());
System.out.println();
List<Player> ranking = getRanking();
System.out.println("转身过人次数排名:");
System.out.println("--------------------------------");
for (int i = 0; i < ranking.size(); i++) {
Player player = ranking.get(i);
System.out.printf("%d. %-10s %d次%n",
i + 1, player.getName(), player.getTurnAroundCount());
}
System.out.println("--------------------------------");
Player topPlayer = getTopTurnAroundPlayer();
if (topPlayer != null) {
System.out.printf("🏆 转身过人次数最多的球员: %s (%d次)%n%n",
topPlayer.getName(), topPlayer.getTurnAroundCount());
}
}
}
// 主类
public class BasketballTurnAroundStats {
public static void main(String[] args) {
System.out.println("=== 篮球转身过人统计系统 ===");
System.out.println();
// 创建比赛统计实例
BasketballGameStats gameStats = new BasketballGameStats();
// 添加球员
String[] players = {"科比", "詹姆斯", "杜兰特", "库里", "字母哥"};
for (String player : players) {
gameStats.addPlayer(player);
}
// 模拟比赛数据(模拟一场48分钟的比赛,期间记录动作)
simulateGame(gameStats);
// 输出统计结果
gameStats.printSummary();
// 展示详细记录
System.out.println("\n各球员转身过人详细记录:");
for (String playerName : players) {
Player player = gameStats.getPlayer(playerName);
if (player != null) {
System.out.printf("%s (%d次): ",
player.getName(), player.getTurnAroundCount());
player.getActions().stream()
.filter(a -> a.getType() == ActionType.TURN_AROUND)
.forEach(a -> System.out.printf("%s ", a));
System.out.println();
}
}
}
// 模拟比赛数据
private static void simulateGame(BasketballGameStats gameStats) {
// 模拟比赛中的动作(这里使用随机数生成模拟数据)
java.util.Random random = new java.util.Random();
String[] playerNames = {"科比", "詹姆斯", "杜兰特", "库里", "字母哥"};
ActionType[] actionTypes = ActionType.values();
// 模拟48分钟的比赛(2880秒)
for (int second = 0; second < 2880; second += 5) {
// 随机选择球员和动作
String playerName = playerNames[random.nextInt(playerNames.length)];
ActionType actionType = actionTypes[random.nextInt(actionTypes.length)];
// 记录动作
gameStats.recordAction(playerName, actionType, second);
}
}
}
增强版 - 添加更详细的统计和分析功能:
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.Date;
// 扩展的统计类,增加更多功能
class AdvancedBasketballStats extends BasketballGameStats {
private Map<String, Map<ActionType, Integer>> actionCounts;
public AdvancedBasketballStats() {
super();
this.actionCounts = new HashMap<>();
}
// 记录动作时同时更新统计信息
@Override
public void recordAction(String playerName, ActionType actionType, int timestamp) {
super.recordAction(playerName, actionType, timestamp);
actionCounts.computeIfAbsent(playerName, k -> new HashMap<>())
.merge(actionType, 1, Integer::sum);
}
// 计算转身过人效率(每分钟转身次数)
public double getTurnAroundRate(String playerName) {
Player player = getPlayer(playerName);
if (player == null) return 0;
double minutes = 48.0; // 标准比赛时间
return player.getTurnAroundCount() / minutes;
}
// 保存统计结果到文件
public void saveStatsToFile(String filename) {
try (PrintWriter writer = new PrintWriter(new FileWriter(filename))) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
writer.println("篮球转身过人统计报告");
writer.println("生成时间: " + sdf.format(new Date()));
writer.println("================================");
for (Player player : getRanking()) {
writer.printf("球员: %-10s 转身过人: %d次%n",
player.getName(), player.getTurnAroundCount());
}
System.out.println("统计数据已保存到文件: " + filename);
} catch (IOException e) {
System.err.println("保存文件时出错: " + e.getMessage());
}
}
// 可视化转身过人数据
public void visualizeTurnAround() {
System.out.println("\n转身过人次数可视化:");
System.out.println("================================");
for (Player player : getRanking()) {
int count = player.getTurnAroundCount();
System.out.printf("%-10s | ", player.getName());
for (int i = 0; i < count; i++) {
System.out.print("█");
}
System.out.printf(" (%d次)%n", count);
}
}
}
// 主程序
public class BasketballTurnAroundStats {
public static void main(String[] args) {
// 前面代码保持不变...
// 创建高级统计实例
AdvancedBasketballStats advancedStats = new AdvancedBasketballStats();
// 添加球员并模拟比赛
// ... (与之前相同的初始化代码)
// 输出可视化结果
advancedStats.visualizeTurnAround();
// 保存数据到文件
advancedStats.saveStatsToFile("basketball_turnaround_stats.txt");
}
}
程序运行结果示例:
=== 篮球转身过人统计系统 ===
========== 比赛统计摘要 ==========
比赛时间: 2880秒
参与球员数: 5
转身过人次数排名:
--------------------------------
1. 科比 12次
2. 詹姆斯 10次
3. 字母哥 8次
4. 杜兰特 7次
5. 库里 5次
--------------------------------
🏆 转身过人次数最多的球员: 科比 (12次)
各球员转身过人详细记录:
科比 (12次): [120秒] [235秒] [340秒] ...
詹姆斯 (10次): [145秒] [260秒] ...
核心功能说明:
- 球员管理:添加球员,记录每个球员的数据
- 动作记录:记录各种篮球动作,特别标注转身过人
- 统计分析:统计每个球员的转身过人次数
- 排名功能:按转身过人次数进行排序
- 可视化展示:用图形化方式展示统计结果
- 文件保存:可以将统计结果保存到文件
这个系统可以灵活运用于:
- 真实比赛的数据统计
- 数据分析师的工作
- 教练评估球员表现
- 球迷互动娱乐
您可以根据实际需求调整代码,比如添加更多统计维度、实时数据更新、数据库存储等功能。
版权声明:NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
足球直播
足球直播
足球直播
篮球直播
篮球直播
篮球直播
NBA直播
NBA直播
NBA直播
CBA直播
CBA直播
CBA直播
亚冠直播
亚冠直播
亚冠直播
欧冠直播
欧冠直播
欧冠直播
英超直播
英超直播
英超直播
西甲直播
西甲直播
西甲直播
中超直播
中超直播
中超直播
足球直播
足球直播
足球直播
篮球直播
篮球直播
篮球直播
NBA直播
NBA直播
NBA直播
CBA直播
CBA直播
CBA直播
亚冠直播
亚冠直播
亚冠直播
欧冠直播
欧冠直播
欧冠直播
英超直播
英超直播
英超直播
西甲直播
西甲直播
西甲直播
中超直播
中超直播
中超直播
足球直播
足球直播
足球直播
篮球直播
篮球直播
篮球直播
NBA直播
NBA直播
NBA直播
CBA直播
CBA直播
CBA直播
亚冠直播
亚冠直播
亚冠直播
欧冠直播
欧冠直播
欧冠直播
英超直播
英超直播
英超直播
西甲直播
西甲直播
西甲直播
中超直播
中超直播
中超直播
足球直播
足球直播
足球直播
篮球直播
篮球直播
篮球直播
NBA直播
NBA直播
NBA直播
CBA直播
CBA直播
CBA直播
亚冠直播
亚冠直播
亚冠直播
欧冠直播
欧冠直播
欧冠直播
英超直播
英超直播
英超直播
西甲直播
西甲直播
西甲直播
中超直播
中超直播
中超直播
曼联直播
曼联直播
曼联直播
日职联直播
日职联直播
日职联直播
澳超直播
澳超直播
澳超直播
阿森纳直播
阿森纳直播
阿森纳直播
足球直播
足球直播
足球直播
NBA直播
NBA直播
NBA直播
曼联直播
曼联直播
曼联直播
日职联直播
日职联直播
日职联直播
澳超直播
澳超直播
澳超直播
阿森纳直播
阿森纳直播
阿森纳直播
足球直播
足球直播
足球直播
NBA直播
NBA直播
NBA直播
曼联直播
曼联直播
曼联直播
日职联直播
日职联直播
日职联直播
澳超直播
澳超直播
澳超直播
阿森纳直播
阿森纳直播
阿森纳直播
足球直播
足球直播
足球直播
NBA直播
NBA直播
NBA直播
曼联直播
曼联直播
曼联直播
日职联直播
日职联直播
日职联直播
澳超直播
澳超直播
澳超直播
阿森纳直播
阿森纳直播
阿森纳直播
足球直播
足球直播
足球直播
NBA直播
NBA直播
NBA直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
足球直播
足球直播
足球直播
足球直播
足球直播
英超直播
英超直播
英超直播
英超直播
英超直播
篮球直播
篮球直播
篮球直播
篮球直播
篮球直播
CBA直播
CBA直播
CBA直播
CBA直播
CBA直播
中超直播
中超直播
中超直播
中超直播
中超直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
足球直播
足球直播
足球直播
足球直播
足球直播
英超直播
英超直播
英超直播
英超直播
英超直播
篮球直播
篮球直播
篮球直播
篮球直播
篮球直播
CBA直播
CBA直播
CBA直播
CBA直播
CBA直播
中超直播
中超直播
中超直播
中超直播
中超直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播