Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. Create a file Game.java which will implement a class of objects that will store some information about one hockey game. In your file, implement

1. Create a file Game.java which will implement a class of objects that will store some information about one hockey game. In your file, implement the following variables and methods.

  1. private instance variables that will store references to two HockeyTeam objects representing the teams that are playing in this game (the home team and the away team).

  2. private instance variables that will store the current score (one int per team).

  3. a constructor that will accept two HockeyTeam parameters, home team first. The score

    should be initialized to 0-0.

  4. the usual public method String toString() which will return a String giving the status of the game, in the format "Winnipeg(2) at Chicago(1)" where the away team is listed first and the home team is listed second, and the score is given as shown. Note that only the team names are shown, not the records of the teams.

  5. a public method void goal(HockeyTeam) which will update the score due to a goal being scored by the indicated team. If that team isnt one of the two that are playing in

    this game, it should use System.out.println to print the error message "That team isn't playing in this game!"

2. Look at this file to see how it is using your Game objects. If your class is working correctly the output should be:

Creating Chicago at Winnipeg game. Chicago(0) at Winnipeg(0) Creating Colorado at St. Louis game. St. Louis(0) at Colorado(0)

Chicago scores Chicago(1) at Winnipeg(0) Winnipeg scores Chicago(1) at Winnipeg(1) St. Louis scores St. Louis(1) at Colorado(0) Colorado scores St. Louis(1) at Colorado(1) Chicago scores in the wrong game: That team isn't playing in this game! St. Louis scores in the wrong game: That team isn't playing in this game! Winnipeg scores Chicago(1) at Winnipeg(2)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Define organisational structure

Answered: 1 week ago

Question

Define line and staff authority

Answered: 1 week ago

Question

Define the process of communication

Answered: 1 week ago

Question

Explain the importance of effective communication

Answered: 1 week ago

Question

* What is the importance of soil testing in civil engineering?

Answered: 1 week ago

Question

The Functions of Language Problems with Language

Answered: 1 week ago

Question

The Nature of Language

Answered: 1 week ago