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

c. Design two classes named BaseballPlayer and BasketballPlayer that are child c

ID: 3765925 • Letter: C

Question

c. Design two classes named BaseballPlayer and BasketballPlayer that are child classes of Player. Include a new data field in each class for the player’s position. Include an additional field in the BaseballPlayer class for batting average. Include a new field in the BasketballPlayer class for free-throw percentage. Override the Player class methods that set and output the data so that you accommodate the new fields.

Design an application that instantiates an object for each type and demonstrates all the methods.

Explanation / Answer

class BaseballPlayer descends from Player

            private char Position

            private num BatAverage

public SetPosition (char newPosition)

            Position = newPosition

return

public SetBatAverage(num newAverage)

            Average=newAverage

return

public Print()

            print Number, Name, Position, BatAverage

return

class BasketballPlayer descends from Player

            private char Position

            priave num FreeThrowPct

public SetFreeThrowPct(num newFTPct)

            FreeThrowPct=newFTPct

return

public SetPosition (char newPosition)

            Position = newPosition

return

public Print()

            print Number, Name, Position, FreeThrowPct

return