×
Reviews 4.9/5 Order Now

Java Program to Implement Player Management System Assignment Solution.

June 24, 2024
Dr. Hannah Lynch
Dr. Hannah
🇬🇧 United Kingdom
Java
Dr. Hannah, a distinguished Ph.D. holder from the University of York, brings over a decade of expertise to our service. With an impressive track record of completing 1100+ Java assignments, Dr. Hannah's profound knowledge and extensive experience ensure exemplary solutions tailored to meet your specific requirements.
Key Topics
  • Instructions
    • Objective
  • Requirements and Specifications
Tip of the day
Focus on using functional programming concepts like immutability, higher-order functions, and pattern matching. Avoid unnecessary loops—prefer map, filter, and fold. Test small functions individually to ensure correctness before combining them.
News
In 2025, the open-source IDE Eclipse Theia released its “AI Coding” update featuring a built-in assistant called Theia Coder that supports natural-language prompts and project-wide refactoring—making it especially useful for programming students and academics.

Instructions

Objective

Write a java assignment program to implement player management system.

Requirements and Specifications

program-to-implement-player-management-system-in-java (1)
program-to-implement-player-management-system-in-java 1 (1)

Source Code

PLAYER

/** * Class to create Player objects */ public class Player { /** * Player name */ private String name; /** * Player's team name */ private String teamName; /** * Number of goals */ private int goals; /** Overloaded constrcutor * @param name String * @param teamName String * @param goals int */ public Player(String name, String teamName, int goals) { this.name = name; this.teamName = teamName; this.goals = goals; } public String getName() { return this.name; } public String getTeamName() { return this.teamName; } public int getGoals() { return this.goals; } public void setName(String newName) { this.name = newName; } public void setTeamName(String newTeamName) { this.teamName = newTeamName; } public void setGoals(int newGoals) { this.goals = newGoals; } @Override public String toString() { return String.format("%s (%s): %d goals", getName(), getTeamName(), getGoals()); } }

LEAGUE

import java.io.File; import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class League { private static List players; public League() { players = new ArrayList(); } public static void addPlayer(Player player) { players.add(player); } public static void printLeague() { // Print all players for(Player p: players) { System.out.println(p.toString()); } } public static void printAverageScore() { // Calculate the average score double avg_score = 0.0; // Loop through players for(Player p: players) { avg_score += p.getGoals(); } // Calculate avg avg_score /= (double)players.size(); System.out.println(String.format("The average score is %.2f", avg_score)); } public static void main(String[] args) throws Exception { League l = new League(); // Check that a file name was passed via arguments if(args.length < 1) { System.out.println("You must give the name of the file containing the players data."); return; } // Get name of file String file_name = args[0]; // Create Scanner Scanner reader = new Scanner(new File(file_name)); String line; while(reader.hasNextLine()) { // read line line = reader.nextLine(); // Split String[] row = line.split(","); // Get name, team and goals String name = row[0].strip(); String teamName = row[1].strip(); int goals = Integer.valueOf(row[2].strip()); // Create player object Player player = new Player(name, teamName, goals); // Add to list of players l.addPlayer(player); } // print all players l.printLeague(); // Print average score l.printAverageScore(); // Close scanner reader.close(); } }

Similar Samples

Explore our sample programming assignments at ProgrammingHomeworkHelp.com to witness our expertise firsthand. These examples showcase our proficiency in various languages and complexities, ensuring high-quality solutions tailored to academic and professional requirements. Dive into our samples to see how we can assist you effectively with your programming challenges.