import java.util.ArrayList;
import java.util.List;
class NBAPlayer {
private String name;
private int jerseyNumber;
// Constructor for creating NBAPlayer objects
public NBAPlayer(String name, int jerseyNumber) {
this.name = name;
this.jerseyNumber = jerseyNumber;
}
// Getter method for retrieving the player's name
public String getName() {
return name;
}
// Getter method for retrieving the player's jersey number
public int getJerseyNumber() {
return jerseyNumber;
}
// Override the toString() method to provide a custom string representation of the player
@Override
public String toString() {
return "Player: " + name + " (#" + jerseyNumber + ")";
}
}
class NBATeam {
private String name;
private List<NBAPlayer> roster;
// Constructor for creating NBATeam objects
public NBATeam(String name) {
this.name = name;
this.roster = new ArrayList<>();
}
// Method to add a player to the team's roster
public void addPlayer(NBAPlayer player) {
roster.add(player);
}
// Method to display the team's roster
public void displayRoster() {
System.out.println("Roster for " + name + ":");
for (NBAPlayer player : roster) {
System.out.println(player);
}
System.out.println();
}
}
public class Main {
public static void main(String[] args) {
// Create two NBA teams
NBATeam lakers = new NBATeam("Los Angeles Lakers");
NBATeam warriors = new NBATeam("Golden State Warriors");
// Add players to the teams
lakers.addPlayer(new NBAPlayer("LeBron James", 23));
lakers.addPlayer(new NBAPlayer("Anthony Davis", 3));
warriors.addPlayer(new NBAPlayer("Stephen Curry", 30));
warriors.addPlayer(new NBAPlayer("Klay Thompson", 11));
// Display the rosters of both teams
lakers.displayRoster();
warriors.displayRoster();
}
}
// Entry point of the program, calling the main() method to execute the code
Main.main(null);
Roster for Los Angeles Lakers:
Player: LeBron James (#23)
Player: Anthony Davis (#3)
Roster for Golden State Warriors:
Player: Stephen Curry (#30)
Player: Klay Thompson (#11)
LA Galaxy 3 - 3 Seattle Sounders
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;
class NFLTeam {
private String name;
private String city;
// Constructor for creating NFLTeam objects with a name and city
public NFLTeam(String name, String city) {
this.name = name;
this.city = city;
}
// Method to get the full name of the NFL team (city + name)
public String getFullName() {
return city + " " + name;
}
}
class NFLPlayer {
private String name;
private String position;
// Constructor for creating NFLPlayer objects with a name and position
public NFLPlayer(String name, String position) {
this.name = name;
this.position = position;
}
// Getter method for retrieving the player's name
public String getName() {
return name;
}
// Getter method for retrieving the player's position
public String getPosition() {
return position;
}
}
public class NFLDraftSimulator {
public static void main(String[] args) {
// Create a list of NFL teams
List<NFLTeam> teams = new ArrayList<>();
teams.add(new NFLTeam("Patriots", "New England"));
teams.add(new NFLTeam("Packers", "Green Bay"));
teams.add(new NFLTeam("Chiefs", "Kansas City"));
// Add more NFL teams...
// Create a list of NFL players
List<NFLPlayer> players = new ArrayList<>();
players.add(new NFLPlayer("Tom Brady", "Quarterback"));
players.add(new NFLPlayer("Aaron Rodgers", "Quarterback"));
players.add(new NFLPlayer("Travis Kelce", "Tight End"));
// Add more NFL players...
// Shuffle the draft order (randomize the order in which teams select players)
Collections.shuffle(teams);
// Simulate the NFL draft
for (int i = 0; i < teams.size(); i++) {
NFLTeam team = teams.get(i);
NFLPlayer player = players.get(i);
// Display the draft results for each round
System.out.println("Round " + (i + 1) + ": " + team.getFullName() + " selects " + player.getName() + " (" + player.getPosition() + ")");
}
}
}
NFLDraftSimulator.main(null)
Round 1: Green Bay Packers selects Tom Brady (Quarterback)
Round 2: New England Patriots selects Aaron Rodgers (Quarterback)
Round 3: Kansas City Chiefs selects Travis Kelce (Tight End)