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

Part I Take me out to the ball game¯. Take me out to the crowd¯. Okay, I will st

ID: 3707469 • Letter: P

Question

Part I

Take me out to the ball game¯. Take me out to the crowd¯. Okay, I will stop singing. We are going to create a program that creates a MLB Baseball Franchise. I will create the interface you will have to implement and the abstract class you will have to extend. The abstract class will be the guideline for creating a baseball team in the MLB (Major League Baseball). The interface will be a template for creating a player for a baseball team. Lastly, you will create a class that will implement the CreateGame interface. This class will simulate a game played between two teams. The simulation will run in a class called PlayBall.

Implement the CreatePlayer Interface

Extend the Team Abstract Class

Implement the CreateGame Interface

Run the game

Show the current score while game is played after each inning.

Show the final score when the game ends.

Determine the winner and print the winner’s name and final score

Part II

Give an example of where you would use an Interface for a programming problem. Give an example of where you would use an Abstract Class for a programming problem.

Part III

Explain what polymorphism is and what encapsulation is. Create a programming example and paste it into the document with an explanation of how it meets the requirements of polymorphism and encapsulation.

Explanation / Answer

Part III)Answer:

polymorphism:

Polymorphism is an object-oriented programming concept that refers to the ability of a variable, function or object to take on multiple forms. A language that features polymorphism allows developers to program in the general rather than program in the specific.

ability to process objects differently depending on their data type or class. More specifically, it is the ability to redefine methods for derived classes.

In a programming language that exhibits polymorphism, objects of classes belonging to the same hierarchical tree (inherited from a common base class) may possess functions bearing the same name, but each having different behaviors.

As an example, assume there is a base class named Animals from which the subclasses Horse, Fish and Bird are derived. Also assume that the Animals class has a function named Move, which is inherited by all subclasses mentioned. With polymorphism, each subclass may have its own way of implementing the function. So, for example, when the Move function is called in an object of the Horse class, the function might respond by displaying trotting on the screen. On the other hand, when the same function is called in an object of the Fish class, swimming might be displayed on the screen. In the case of a Bird object, it may be flying.

In effect, polymorphism cuts down the work of the developer because he can now create a sort of general class with all the attributes and behaviors that he envisions for it. When the time comes for the developer to create more specific subclasses with certain unique attributes and behaviors, the developer can simply alter code in the specific portions where the behaviors differ. All other portions of the code can be left as is

Example:

Let us look at an example.

Now, the Deer class is considered to be polymorphic since this has multiple inheritance. Following are true for the above examples ?

When we apply the reference variable facts to a Deer object reference, the following declarations are legal ?

Example

All the reference variables d, a, v, o refer to the same Deer object in the heap.

encapsulation:

Encapsulation,refers to an object's ability to hide data and behavior that are not necessary to its user. Encapsulation enables a group of properties, methods and other members to be considered a single unit or object.

The following are the benefits of encapsulation:

Encapsulation is used to restrict access to the members of a class so as to prevent the user of a given class from manipulating objects in ways that are not intended by the designer. While encapsulation hides the internal implementation of the functionalities of class without affecting the overall functioning of the system, it allows the class to service a request for functionality and add or modify its internal structure (data or methods) to suit changing requirements.

Encapsulation is also known as information hiding

Encapsulation in C# is implemented with different levels of access to object data that can be specified using the following access modifiers:

Encapsulation can be illustrated with an example of an Employee object that stores details of that object. By using encapsulation, the Employee object can expose the data (like Name, EmployeeID, etc.) and methods (like GetSalary) necessary for using the object, while hiding its irrelevant fields and methods from other objects. It is easy to see a situation in which all users could access basic information about an employee while restricting salary information.

C# allows encapsulation of data through the use of accessors (to get data) and mutators (to modify data), which help in manipulating private data indirectly without making it public. Properties are an alternate mechanism for private data to be encapsulated in a C# object and accessed in either read-only mode or in read-write mode. Unlike the accessor and mutator, a property provides a single point of access to an object's "set" and "get" values.

Example:

Following is an example that demonstrates how to achieve Encapsulation in Java ?

The public setXXX() and getXXX() methods are the access points of the instance variables of the EncapTest class. Normally, these methods are referred as getters and setters. Therefore, any class that wants to access the variables should access them through these getters and setters.

The variables of the EncapTest class can be accessed using the following program ?

This will produce the following result ?

Output

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote