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:

  1. Base Class - TeamMember: Create a base class named TeamMember with the following features:

    • Private instance variables for name (String) and jerseyNumber (int).

    • A constructor that initializes name and jerseyNumber.

    • An override the method toString() that prints the name and jersey number of the team member.

  2. Subclass - Player: Create a subclass named Player that inherits from TeamMember:

    • Add an additional private instance variable for position (String).

    • A constructor that initializes name, jerseyNumber, and position.

    • Override the toString() method to also display the player's position.

    • Override the equals() method to compare players.

  3. Subclass - Coach: Create another subclass named Coach that also inherits from TeamMember:

    • Add an additional private instance variable for role (String - head coach, assistant coach etc.).

    • A constructor that initializes name, jerseyNumber, and role.

    • Override the tostring() method to display the coach's role.

    • Override the equals() method to compare coaches.

  4. Main Method: In your main method, perform the following tasks:

    • Create an instance of Player and call its toString() method.

    • Create an instance of Coach and call its toString() method.

 Deliverables

Upload the following files in a zip folder that you have created:

  1. Java class files

  2. Screenshot of the Console with the code executing

 

COSC-1437 / ITSE-2457 Computer Science Dept. - Author: Dr. Kevin Roark