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
There are several vehicles in a parking lot. Some of them are motorcycles
GREYUIT [131]

Answer:

The answer is 34.

Explanation:

Look at the pic.

4 0
3 years ago
Read 2 more answers
What will the following code display?
nikitadnepr [17]

Answer:

Answer is C) 3

Explanation:

7 0
3 years ago
Write a program to input money in cents from user, example 12745 and display the one dollar bills and the cents. Submit source c
ira [324]

import java.util.*;  //This is used to import the Scanner

class Main {

 public static void main(String[] args) {

   System.out.println("Hello world!");

   Scanner ValCents = new Scanner (System.in);

   System.out.println("Enter Number:");

   int user_input = ValCents.nextInt();

   int result = user_input/100;  // This one will solve for the one dollar bills.

   int remain = user_input % 100;  // This one will get the remainder of cents.

   System.out.println(result + " One Dollar Bills");

   System.out.println(remain + " Cents");

 }

}

Remember that you need to get the amount of dollar bills separately from the number of cents. This is because the int variable will always return the whole value of the number. The modulo is used to get the variable of the cents as the whole number is already taken by the "result".

6 0
4 years ago
Write a program that:
skad [1K]

Answer:

sucks to suck

Explanation:

4 0
3 years ago
Eliza needs to share contact information with another user, but she wants to include only certain information in the contact. Wh
Maslowich

Answer:

Use the edit business card dialog box to control the information.

Explanation:

Business card is an easiest way to share contact details with other persons. There are some reasons a person might not want to share entire details of the contact it has with the other person, for this purpose the business card outlook has an option to edit the information of contact before sending it to the other person. Click the contact card and select the relevant contact that needs to be shared, then double click the contact it will display an edit option.

6 0
3 years ago
Read 2 more answers
Other questions:
  • Mass production usually uses an _______________ ____________ or production line technique.
    7·1 answer
  • The issue with discovering a perfect solution to a problem is that ________.
    10·2 answers
  • At the aquarium Grandma Simpson hugged the dolphin is that passive or active sentence​?
    6·1 answer
  • The famous study entitled ""Protection Analysis: Final Report"" focused on a project undertaken by ARPA to understand and detect
    14·1 answer
  • The CMS Quarterly Provider Update (QPU) is an online CMS publication that contains information about __________ currently under
    14·1 answer
  • A browser allows you to set preferences for using the browser. These preferences include all of the following except
    7·1 answer
  • A style ____ is a series of rules that defines the style for a web page or an entire web site.
    6·1 answer
  • Define a function pyramid_volume with parameters base_length, base_width, and pyramid_height, that returns the volume of a pyram
    6·2 answers
  • The getElementById DOM Method do?
    13·1 answer
  • B. WAP to check whether input number is palindrome number or not using SUB...... END SUB.​
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!