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
What are the letter that go under each note?
gladu [14]

Answer:

A, B, C, D, E, F, G pls mark me brainliest see explanation below

Explanation:

those are the letters if you search up letters for music you can find them way easier than me explaining and you will also learn faster. please mark me brainliest

5 0
2 years ago
Read 2 more answers
Which of the following could have a negative impact a planned route?
Nata [24]

Answer:

B

Explanation:

8 0
3 years ago
Which tab is used to configure an export to PST in Outlook 2016?
Blizzard [7]

Answer:

file

Explanation:

you should go through the file so as to configure it

3 0
3 years ago
Read 2 more answers
Write a program that simulates picking a card from a deck of 52 cards. Your program should display the rank (Ace, 2, 3, 4, 5, 6,
Artyom0805 [142]

Answer:

Explanation:

The following is a python function that has arrays with all the cards available and then uses random to choose a random card from the dictionary. Finally it prints out the card chosen...

import random

def choose_card():

   card = ["Ace", 2, 3, 4, 5, 6, 7, 8, 9, 10, 'Jack', 'Queen', 'King']

   symbols = ['Clubs', 'Diamonds', 'Hearts', 'Spades']

   chosen_card = str(card[random.randint(0, len(card))])

   symbols = symbols[random.randint(0, len(symbols))]

   print("Chosen Card: " + chosen_card + " of " + symbols)

7 0
2 years ago
To assign a new keyboard shortcut, you would access backstage, word options then
Zarrin [17]
Customize ribbon, and the customize button.
6 0
2 years ago
Other questions:
  • The section called Breaking Substitution Ciphers (p. 166) describes a "random substitution cipher," in which each letter of the
    11·1 answer
  • 5(x + 4) = 4(x -6) |<br><br><br>How to do this problem
    10·1 answer
  • When cleaning a firearm, what end of the firearm should you generally clean from?
    11·2 answers
  • Write a method called findNames that meets the following specs: It takes two arguments: a list of strings, allNames, and a strin
    12·1 answer
  • Which is an unethical use of technology and resources at the workplace?
    13·2 answers
  • You change a document that is saved on your computer by cutting text from the document what happens to the text when you preform
    5·1 answer
  • What is a orogram to block access to websites
    15·1 answer
  • To achieve asymptotically optimal performance, a skip list must use promotion probability . true or false and
    14·1 answer
  • Generally, websites ending in .edu, .gov, and .org are less likely to be biased, or to show preference toward a certain financia
    12·1 answer
  • Brianna is taking a backpacking trip in the wilderness and wants to back up the photos from her camera. Which type of storage de
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!