This commit is contained in:
2024-12-31 14:58:42 +03:00
parent db2dbc5c19
commit b050db6dce
16 changed files with 323 additions and 1 deletions

43
labs/lab7/Player.java Normal file
View File

@ -0,0 +1,43 @@
// **********************************************************
// Player.java
//
// Defines a Player class that holds information about an athlete.
// **********************************************************
import java.util.Scanner;
public class Player
{
private String name;
private String team;
private int jerseyNumber;
//-----------------------------------------------------------
// Prompts for and reads in the player's name, team, and
// jersey number.
//-----------------------------------------------------------
public void readPlayer()
{
Scanner scan = new Scanner(System.in);
System.out.print("Name: ");
name = scan.nextLine();
System.out.print("Team: ");
team = scan.nextLine();
System.out.print("Jersey number: ");
jerseyNumber = Scan.nextInt();
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true; // Check if the two references are the same
if (obj == null || getClass() != obj.getClass()) return false; // Ensure obj is a Player
Player other = (Player) obj; // Typecast obj to Player
return team.equals(other.team) && jerseyNumber == other.jerseyNumber;
}
//-----------------------------------------------------------
// Returns a string representation of the player.
//-----------------------------------------------------------
@Override
public String toString() {
return "Name: " + name + ", Team: " + team + ", Jersey Number: " + jerseyNumber;
}
}