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]
3 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]3 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
PLEASE HELP ME !!!!
Sedaia [141]

Answer:

Complete the ZipZapZop()

function so that it requests an integer from the user. The function should display a response following this pattern:

• Divisible by 3: zip

• Divisible by 5 zap

• Divisible by 7 zop

Otherwise, just display the number

Note 1 numbers that are divisible by more than one (3, 5, or 7) should contain

all applicable terms.

Notes 2 Note that you are displaying directly from this function, not returning a value to the calling function.

Hint: The number only prints if it is not divisible by ALL of 3,5,or 7

Explanation:

3 0
3 years ago
PLEASE HELP!
Morgarella [4.7K]
An query because his ideas are effective
8 0
4 years ago
Read 2 more answers
What does cramming to hand in an assignment
Vikki [24]
Honestly gotta say cramming in an assignment doesnt help at all

5 0
3 years ago
During the _____ of the systems development life cycle (SDLC), an information system is operating, enhancements and modification
Neporo4naja [7]

Answer:

Maintenance Phase

Explanation:

One of the concepts employed in project management for describing stages involved when carrying out an information system development project is the systems development life cycle (SLDC). The cycle which starts from carrying out a feasibility study and ends in maintenance is a highly used conceptual model. There are 5 major stages or phase and they are the; Requirement Phase, Design Phase; Implementation Phase, Test Phase, and the Maintenance phase. The maintenance phase comes when testing has been complete and all enhancement and modifications have already been developed, and the system is operating.

5 0
3 years ago
Here are a list of attributes that either belong to user model or system model. Please identify which attribute(s) belong to use
OverLord2011 [107]

Answer:

Explanation:

Before answering this question we need to first know the differences between System Mode and User Mode.

System Mode mainly runs code and at the same time overlooking the user's privileges and permissions.

the attribute(s) that belongs to the user model includes:

User Mode

  1. User programs typically execute in this mode
  2. Less-privilege mode

while the attribute(s) that belongs to the system model includes:

System Mode

  1. Also referred to as control mode or kernel mode
  2. Kernel of the operating system
  3. More-privilege mode

8 0
3 years ago
Other questions:
  • Discuss OPENGL instruction to draw the following drawing primatives:
    14·1 answer
  • To copy and paste from an excel workbook to a word document, you must first
    6·1 answer
  • A child with suspected sleep apnea was given an apnea monitoring device to use over the next month. The device was capable of re
    6·1 answer
  • Explain why it might be more appropriate to declare an attribute that contains only digits as a character data type instead of a
    11·1 answer
  • You create a new three-way mirror storage space. You format the storage space by using ReFS. Which two features can you use on t
    13·1 answer
  • Do most good businesses have to deal with conflict
    7·1 answer
  • In computer Drag and Drop“ means to select the items, hold down the mouse and
    15·1 answer
  • To comply with ATC instructions for altitude changes of more than 1,000 feet, what rate of climb or descent should be used?
    5·1 answer
  • in a typical e-mail address, the "host" is A. an account designated by a user name B. CPU processor 2500 C. the receiver of an e
    12·2 answers
  • To what extent do you agree with the assertion that “Collection development begins with community analysis”. (Give reasons to bu
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!