Question: THIS IS EXERCISE 6 IN c# Apply inheritance to your Exercise 5 . Create a new class called Player that must inherit from an Employee

THIS IS EXERCISE 6
IN c#
Apply inheritance to your Exercise 5.
Create a new class called Player that must inherit from an Employee class
Refactor your code with the new changes.
Demonstrate your new code and show that you can use your classes to have:
3 on 3 basketball3 on 3 flag-football3 on 3 soccer
code for exercise 5:
using System; using System.Collections.Generic; using System.Linq; // Base class for objects with positions on the court public abstract class GameObject { public double X { get; set; } public double Y { get; set; } public GameObject(double x, double y){ X = x; Y = y; }// Calculate the Euclidean distance between two objects public double GetDistance(GameObject other){ return Math.Sqrt(Math.Pow(X - other.X,2)+ Math.Pow(Y - other.Y,2)); }}// Represents a basketball player public class Player : GameObject { public string Name { get; private set; } public string Team { get; private set; } public Player(string name, string team, double x, double y) : base(x, y){ Name = name; Team = team; }}// Represents the referee public class Referee : GameObject { public Referee(double x, double y) : base(x, y){}}// Represents the basketball public class Basketball : GameObject { public Basketball(double x, double y) : base(x, y){}}// Represents a basket on the court public class Basket { public double X { get; private set; } public double Y { get; private set; } public string Team { get; private set; } public static readonly double Width =3; public static readonly double Height =2; public Basket(double x, double y, string team){ X = x; Y = y; Team = team; } public bool IsBallInside(Basketball ball){ return ball.X >= X -(Width /2) && ball.X <= X +(Width /2) && ball.Y >= Y -(Height /2) && ball.Y <= Y +(Height /2); }}// Represents the basketball game and its logic public class BasketballGame { private List players; private List baskets; private Referee referee; private Basketball basketball; private const double CourtWidth =10.0; private const double CourtHeight =10.0; public BasketballGame(){ players = new List(); baskets = new List(); InitializeGame(); } private void InitializeGame(){// Create players players.Add(new Player("Alice", "Team A",2,3)); players.Add(new Player("Bob", "Team A",4,2)); players.Add(new Player("Charlie", "Team A",1,1)); players.Add(new Player("David", "Team B",6,7)); players.Add(new Player("Eve", "Team B",8,6)); players.Add(new Player("Frank", "Team B",7,4)); // Create referee referee = new Referee(5,5); // Place basketball basketball = new Basketball(10,5); // Create baskets baskets.Add(new Basket(0,5, "Team B")); // Team A's scoring basket baskets.Add(new Basket(10,5, "Team A")); // Team B's scoring basket }// Method to get all players' positions public List<(string Name, double X, double Y)> GetAllPlayersPositions(){ return players .Select(p =>(p.Name, p.X, p.Y)).ToList(); }// Method to get players sorted by their distance to the referee public List<(string Name, double Distance)> GetPlayersSortedByDistanceToReferee(){ return players .Select(p =>(p.Name, Distance: p.GetDistance(referee))).OrderBy(p => p.Distance).ToList(); }// Method to determine if a basket has been scored public (bool Scored, string Team) CheckIfBasketScored(){ foreach (var basket in baskets){ if (basket.IsBallInside(basketball)){ return (true, basket.Team); }} return (false, null); }// Method to move the basketball to a new position public void MoveBasketball(double newX, double newY){ if (newX <0|| newX > CourtWidth || newY <0|| newY > CourtHeight){ throw new ArgumentException("New position out of the court boundaries!"); } basketball.X = newX; basketball.Y = newY; }// Method to move a player to a new position public void MovePlayer(string playerName, double newX, double newY){ var player = players.FirstOrDefault(p => p.Name == playerName); if (player == null){ throw new ArgumentException($"Player {playerName} does not exist."); } if (newX <0|| newX > CourtWidth || newY <0|| newY > CourtHeight){ throw new ArgumentException("New position out of the court boundaries!"); } player.X = newX; player.Y = newY; }}// Main Program to demonstrate the functionality class Program { static void Main(string[] args){// Initialize the game BasketballGame game = new BasketballGame(); // Showcase all players'

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!