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

Java Programming Concepts: Multiple Objects, Abstract Classes, Interfaces, Inher

ID: 3738707 • Letter: J

Question

Java Programming

Concepts: Multiple Objects, Abstract Classes, Interfaces, Inheritance, Method Overriding

.....................

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 an 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

public abstract class Team {

               

                public final int rosterCount = 9;

               

                public abstract void setTeamName(String name);

               

                public abstract String getTeamName();

               

                public abstract void setTeamCity(String city);

               

                public abstract String getTeamCity();

               

                public int getRoster(){

                                return rosterCount;

                }

}

public interface CreateGame {

               

                public abstract void runGame();

                //should run the game as a simulation that automatically plays the whole game until end of 9 innings.

               

                public abstract String printAfterInning();

                //should print score for each team after each inning

               

                public abstract String printWinnerAfterGame();

                //should print the winner and final score after game completed

}

public interface CreatePlayer {

               

                public abstract void setPlayerName(String name);

               

                public abstract String getPlayerName();

               

                public abstract void setPlayerPosition(String position);

               

                public abstract String getPlayerPosition();

               

                public abstract void setPlayerAge(int age);

               

                public abstract int getPlayerAge();

               

}

Explanation / Answer

import java.util.*;
import java.io.*;

public abstract class Team {

   public final int rosterCount = 9;

   public abstract void setTeamName(String name);

   public abstract String getTeamName();

   public abstract void setTeamCity(String city);

   public abstract String getTeamCity();

   public int getRoster(){
        return rosterCount;
   }

}

public interface CreateGame {

   public abstract void runGame();

   //should run the game as a simulation that automatically plays the whole game until end of 9 innings.

   public abstract String printAfterInning();

   //should print score for each team after each inning

   public abstract String printWinnerAfterGame();

   //should print the winner and final score after game completed

}

public class Game implements CreateGame {
   public void runGame(){

   }

   public String printAfterInning() {
       int scoreA = 0, scoreB = 0;
       return "Score after inning: Team A : " + scoreA + " and Team B : " + scoreB;
   }

   public String printWinnerAfterGame() {
       int scoreA = 0, scoreB = 0;
       return "Score after game: Team A : " + scoreA + " and Team B : " + scoreB;
   }
}

public interface CreatePlayer {

    public abstract void setPlayerName(String name);

    public abstract String getPlayerName();

    public abstract void setPlayerPosition(String position);

    public abstract String getPlayerPosition();

    public abstract void setPlayerAge(int age);

    public abstract int getPlayerAge();

}

public class Player implements CreatePlayer {
  
   String name;
   String position;
   int age;

   public void setPlayerName(String name1) {
       name = name1;
   }

   public String getPlayerName() {
       return name;
   }

   public void setPlayerPosition(String position1) {
       position = position1;
   }

   public String getPlayerPosition() {
       return position;
   }

   public void setPlayerAge(int age1) {
       age = age1;
   }

   public int getPlayerAge() {
       return age;
   }
}

class PlayBall implements CreateGame {
   public static void main(String args[]) {
      
   }
}

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