1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Gnoma [55]
2 years ago
12

Create a class named BaseballGame that contains data fields for two team names and scores for each team in each of nine innings.

names should be an array of two strings and scores should be a two-dimensional array of type int; the first dimension indexes the team (0 or 1) and the second dimension indexes the inning. Create get and set methods for each field. The get and set methods for the scores should require a parameter that indicates which inning’s score is being assigned or retrieved. Do not allow an inning score to be set if all the previous innings have not already been set. If a user attempts to set an inning that is not yet available, issue an error message. Also include a method named display in DemoBaseballGame.java that determines the winner of the game after scores for the last inning have been entered. (For this exercise, assume that a game might end in a tie.) Create two subclasses from BaseballGame: HighSchoolBaseballGame and LittleLeagueBaseballGame. High school baseball games have seven innings, and Little League games have six innings. Ensure that scores for later innings cannot be accessed for objects of these subtypes.
Computers and Technology
1 answer:
m_a_m_a [10]2 years ago
6 0

Answer:

Check the explanation

Explanation:

BaseballGame:

public class BaseballGame {

  protected String[] names = new String[2];

  protected int[][] scores;

  protected int innings;

  public BaseballGame() {

      innings = 9;

      scores = new int[2][9];

      for(int i = 0; i < 9; i++)

          scores[1][i] = scores[0][i] = -1;

  }

 

  public String getName(int team) {

      return names[team];

  }

  public void setNames(int team, String name) {

      names[team] = name;

  }

 

  public int getScore(int team, int inning) throws Exception {

      if(team < 0 || team >= 2)

          throw new Exception("Team is ut of bounds.");

      if(inning < 0 || inning >= innings)

          throw new Exception("Inning is ut of bounds.");

     

      return scores[team][inning];

  }

  public void setScores(int team, int inning, int score) throws Exception {

      if(team < 0 || team >= 2)

          throw new Exception("Team is ut of bounds.");

      if(inning < 0 || inning >= innings)

          throw new Exception("Inning is ut of bounds.");

      if(score < 0)

          throw new Exception("Score is ut of bounds.");

      for(int i = 0; i < inning; i++)

          if(scores[team][i] == -1)

              throw new Exception("Previous scores are not set.");

     

      scores[team][inning] = score;

  }

 

}

HighSchoolBaseballGame:

public class HighSchoolBaseballGame extends BaseballGame {

  public HighSchoolBaseballGame() {

      innings = 7;

      scores = new int[2][7];

      for(int i = 0; i < 7; i++)

          scores[1][i] = scores[0][i] = -1;

  }

}

LittleLeagueBaseballGame:

public class LittleLeagueBaseballGame extends BaseballGame {

  public LittleLeagueBaseballGame() {

      innings = 6;

      scores = new int[2][6];

      for(int i = 0; i < 6; i++)

          scores[1][i] = scores[0][i] = -1;

  }

}

You might be interested in
Linda subscribes to a cloud service. The service provider hosts the cloud infrastructure and delivers computing resources over t
siniylev [52]

Answer

Public cloud

Explanation

A cloud service is any service that is made available to users who are on demand via internet from the cloud computing service providers.  These service providers have servers in their company premises where they offer the services from.

A public cloud is a type of computing in which a service provider makes resources available to the public via the internet. The service provider hosts the cloud infrastructure and delivers computing resources over the Internet Resources vary by provider but may include storage capabilities, applications or virtual machines.


3 0
3 years ago
Help me please with this
LUCKY_DIMON [66]

Answer:

Explanation:

QUestion 2 is A

QUestion 1 is A i think

7 0
2 years ago
When should you talk to an adult you trust
Gnesinka [82]

Answer:

you should talk to them when u think its the right time and you think u can trust them

5 0
3 years ago
QUESTION 1
slava [35]
Answer is Bit defender Internet security
B
6 0
2 years ago
If you are going to develop a special computer, what would it be and explain it's purpose.​
Ann [662]

Answer:

It would be to figure out what cancers someone could exactly so no need for a biopsy

4 0
3 years ago
Other questions:
  • An effectively distributed resume will get an interview
    12·2 answers
  • he specific gravity of gold is 19.3. Write a MATLAB program that will ask the user to input the mass of a cube of solid gold in
    15·1 answer
  • 1. A tachometer measures:
    8·1 answer
  • Find the range of the function for the domain<br>(-4,-2,0, 1.5,4).<br>f(x) = 5x²+ 4<br>​
    13·1 answer
  • What is trouble shoot​
    11·1 answer
  • Why is it important to study in a quiet well lit area
    5·2 answers
  • In this challenge, write a function to add two floating point numbers. Determine the integer floor of the sum. The floor is the
    8·1 answer
  • Complete the method, print Multiples(), that takes in a positive integer n, and another positive integer, max. Print out all the
    15·1 answer
  • Match the characteristics to the mobile operating system that it describes.
    11·1 answer
  • Tom is not sure how to code contents such as title and meta elements. These are coded as ____ elements.
    8·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!