Module 5 - Baseball Team Lab
Objective
The goal of this assignment is to understand the concept of inheritance in Object-Oriented Programming (OOP). You will create a class hierarchy to represent different roles within a baseball team, demonstrating how inheritance can be used to manage these roles.
Requirements:
Base Class - TeamMember: Create a base class named
TeamMember
with the following features:Private instance variables for
name
(String) andjerseyNumber
(int).A constructor that initializes
name
andjerseyNumber
.An override the method
toString()
that prints the name and jersey number of the team member.
Subclass - Player: Create a subclass named
Player
that inherits fromTeamMember
:Add an additional private instance variable for
position
(String).A constructor that initializes
name
,jerseyNumber
, andposition
.Override the
toString()
method to also display the player's position.Override the
equals()
method to compare players.
Subclass - Coach: Create another subclass named
Coach
that also inherits fromTeamMember
:Add an additional private instance variable for
role
(String - head coach, assistant coach etc.).A constructor that initializes
name
,jerseyNumber
, androle
.Override the
tostring()
method to display the coach's role.Override the
equals()
method to compare coaches.
Main Method: In your
main
method, perform the following tasks:Create an instance of
Player
and call itstoString()
method.Create an instance of
Coach
and call itstoString()
method.
Deliverables
Upload the following files in a zip folder that you have created:
Java class files
Screenshot of the Console with the code executing
COSC-1437 / ITSE-2457 Computer Science Dept. - Author: Dr. Kevin Roark