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
IN c#
Apply inheritance to your Exercise
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:
on basketball on flagfootball on soccer
code for exercise :
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 GameObjectdouble x double y X x; Y y; Calculate the Euclidean distance between two objects public double GetDistanceGameObject other return Math.SqrtMathPowX other.X Math.PowY other.Y; Represents a basketball player public class Player : GameObject public string Name get; private set; public string Team get; private set; public Playerstring name, string team, double x double y : basex y Name name; Team team; Represents the referee public class Referee : GameObject public Refereedouble x double y : basex y Represents the basketball public class Basketball : GameObject public Basketballdouble x double y : basex 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 ; public static readonly double Height ; public Basketdouble x double y string team X x; Y y; Team team; public bool IsBallInsideBasketball ball return ball.X X Width && ball.X X Width && ball.Y Y Height && ball.Y Y Height ; 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 ; private const double CourtHeight ; public BasketballGame players new List; baskets new List; InitializeGame; private void InitializeGame Create players players.Addnew PlayerAlice "Team A; players.Addnew PlayerBob "Team A; players.Addnew PlayerCharlie "Team A; players.Addnew PlayerDavid "Team B; players.Addnew PlayerEve "Team B; players.Addnew PlayerFrank "Team B; Create referee referee new Referee; Place basketball basketball new Basketball; Create baskets baskets.Addnew Basket "Team B; Team As scoring basket baskets.Addnew Basket "Team A; Team Bs scoring basket Method to get all players' positions public Liststring Name, double X double Y GetAllPlayersPositions return players Selectp pName, pX pYToList; Method to get players sorted by their distance to the referee public Liststring Name, double Distance GetPlayersSortedByDistanceToReferee return players Selectp pName, Distance: pGetDistancerefereeOrderByp pDistanceToList; Method to determine if a basket has been scored public bool Scored, string Team CheckIfBasketScored foreach var basket in baskets if basketIsBallInsidebasketball return true basket.Team; return false null; Method to move the basketball to a new position public void MoveBasketballdouble newX, double newY if newX newX CourtWidth newY newY CourtHeight throw new ArgumentExceptionNew position out of the court boundaries!"; basketball.X newX; basketball.Y newY; Method to move a player to a new position public void MovePlayerstring playerName, double newX, double newY var player players.FirstOrDefaultp pName playerName; if player null throw new ArgumentException$"Player playerName does not exist."; if newX newX CourtWidth newY newY CourtHeight throw new ArgumentExceptionNew position out of the court boundaries!"; player.X newX; player.Y newY; Main Program to demonstrate the functionality class Program static void Mainstring 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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
