answer.
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]
1 year 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]1 year 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
Write a loop to populate the list user_guesses with a number of guesses. The variable num_guesses is the number of guesses the u
Masja [62]

Answer:

num_guesses = int(input())

user_guesses = []

for i in range(num_guesses):

    x = int(input())

    user_guesses.append(x)

   

print(user_guesses)

Explanation:

This solution is provided in Python

This line prompts the user for a number of guesses

num_guesses = int(input())

This line initializes an empty list

user_guesses = []

This loop lets user input each guess

for i in range(num_guesses):

This line takes user input for each guess

    x = int(input())

This appends the input to a list

    user_guesses.append(x)

This prints the user guesses    

print(user_guesses)

6 0
1 year ago
In three to five sentences, explain how you would insert graphics using your word-processing software.
madam [21]
Most word-processing programs allow the user to select a command from the menu to insert a graphic. Clicks in the document where you want your file, choose insert and picture click from file select the image the press open and you picture will become inserted in to the document.
3 0
2 years ago
Read 2 more answers
Which task can a company perform with intranets?
gregori [183]
I would probably say C, Though you might want a second, person to clarify. But My answer is C..
6 0
2 years ago
Read 2 more answers
Please answer this a due tomorrow!!!
dem82 [27]

Answer:  

4-Well first of all for the "VR" problem it could be a problem, because people could forget about there actual life and not be able to much of anything when needed.

1-the first one you are going to have to answer.

2-If you have different files then you aren't stumbling through multiple different links and could have trouble with finding what is needed.

3-the third one you are going to have to answer.

5-If I were you I would help them the best way you could so they can actually know how to do their job.

5 0
1 year ago
In the Budget Details sheet, if you wish to autofill with the formula, you must use a ______ reference for the LY Spend Total ce
ahrayia [7]

Answer:

The answer is A.Absolute reference.

Explanation:

Absolute reference is a cell reference whose location remains constant when the formula is copied.

8 0
2 years ago
Other questions:
  • ________ is used to undo unwanted database changes.
    15·2 answers
  • Propane also known as LP gas, is often mixed with about _______ percent of other gases, such as butane, propylene, and mercaptan
    13·1 answer
  • An organization has a datacenter manned 24 hours a day that processes highly sensitive information. The datacenter includes emai
    5·1 answer
  • In the game of $Mindmaster$, secret codes are created by placing pegs of any of seven different colors into four slots. Colors m
    5·1 answer
  • Budget Analysis (use while loop) Write a program that asks the user to enter the amount that he or she has budgeted for a month.
    5·1 answer
  • Suppose that each row of an n×n array A consists of 1’s and 0’s such that, in any row i of A, all the 1’s come before any 0’s in
    15·1 answer
  • Sara is using her personal laptop (which is password protected) at a "hotspot" at a local cafe with wifi access. She is in the m
    7·1 answer
  • g 18.6 [Contest 6 - 07/10] Reverse an array Reversing an array is a common task. One approach copies to a second array in revers
    8·1 answer
  • The maximum number of times the decrease key operation performed in Dijkstra's algorithm will be equal to ___________
    14·1 answer
  • Checkpoint 10.43 Write an interface named Nameable that specifies the following methods: _______{ public void setName(String n)
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!