Question
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.
-
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).
-
private instance variables that will store the current score (one int per team).
-
a constructor that will accept two HockeyTeam parameters, home team first. The score
should be initialized to 0-0.
-
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.
-
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started