Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Complete the following tasks: a. Design a class named Player that holds a player

ID: 666796 • Letter: C

Question

Complete the following tasks:

a. Design a class named Player that holds a player number and name for a sportsteam participant. Include methods to set the values for each data field andoutput the values for each data field.

b. Design two classes named BaseballPlayer and BasketballPlayer that arechild classes of Player . Include a new data field in each class for the player ’ sposition. Include an additional field in the BaseballPlayer class for battingaverage. Include a new field in the BasketballPlayer class for free-throw percentage. Override the Player class methods that set and output the data sothat you accommodate the new fields.

c. Design an application that instantiates an object of each type and demonstratesall the methods.

Explanation / Answer

Hi,

Its not mentioned in which language you want the application to be built in.I am assuming and doing it in JAVA.

This is how i have implemented it:

1.Created a super class class AllPlayers which has player number,player name as the attributes,Also i have implemented a method called AllPlayers that displays these above attributes.

2.Created class called baseball player that extends AllPlayers and gets the attributes player no and player name from its super class Allplayers and added new attributes to this class called player position and batting average.Also the method getallbaseballplayers used the base class AllPlayers method and displays all the values.

3.Created class called basket player that extends AllPlayers and gets the attributes player no and player name from its super class Allplayers and added new attributes to this class called player position and Throw average.Also the method getallbasebasketballplayers used the base class AllPlayers method and displays all the values.

4.Finally the main class players creates 3 objects called players,bas,basket for the above classes AllPlayers,Baseballplayers,Basketballplayers respectively and displays all the functions.I have used the constructors that takes all the values from thier class attributes.

package java_project;
public class AllPlayers {
   protected int player_no;
protected String player_name;
  
public AllPlayers(int player_no,String player_name)
{
int play_no=player_no;
String name=player_name;
}

public void player_data()
{
System.out.println(" Player no.=" +play_no);
System.out.println(" Player Name=" +name);
}
}
class Baseballplayer extends AllPlayers{
   int player_position;
   int batting_average;
  
   public Baseballplayer (int player_no,String player_name,int position,int average){
   super(player_no,player_name);
   position=player_position;
   average=batting_average;
  
   }
   public void getbaseballplayerdata()
   {
   System.out.println(" Player no.="+play_no);
   System.out.println("Name="+name);
   System.out.println("Player position ="+position);
   System.out.println("batting average="+average);
   }
}
class Basketballplayer extends AllPlayers{
   int basketballplayer_position;
   int throw_percentage;
  
   public Basketballplayer(int player_no,String player_name,int basketballplayer_position,int throw_percentage ){
  
       super(player_no,player_name);
       int position=this.basketballplayer_position;
       int throw_percent= this.throw_percentage;
      
   }
   public void getbasketballplayerdata(){
       System.out.println(" Player no.="+play_no);
System.out.println("Name="+name);
System.out.println("Player position ="+position);
System.out.println("Throw percentage="+throw_percent);
   }
}
class Players
{
public static void main(String args[])
{
AllPlayers players= new AllPlayers(1,"Varun");
players.player_data();
Baseballplayer bas= new Baseballplayer(2,"Arun",2,80);
bas.getbaseballplayerdata();
Basketballplayer basket= new Basketballplayer(3,"Nithin",5,70);
basket.getbasketballplayerdata();
}
}

output:

nn@linuxmint ~ $ javac players.java
nn@linuxmint ~ $ java players
Player no.=1
Name=Varun

Player no.=2
Name=Arun

Player position=2

batting average=80

Player no.=3
Name=Nithin
Player position=5
Throw percentage=70
nn@linuxmint ~ $