Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Soccer Game package hw5; // Put your name here // Put your collaborator(s) name(s) here public class SoccerGame { private String team1, team2; private int

Soccer Game

package hw5;

// Put your name here // Put your collaborator(s) name(s) here

public class SoccerGame { private String team1, team2; private int team1Score, team2Score; private final int MIN_SCORE = 0; private static int totalGames = 0; private static int totalScore = 0; public SoccerGame() { } public SoccerGame(String t1, String t2) {

} public String getTeam1() { // A stub -- remove when you write this method return ""; } public String getTeam2() { // A stub -- remove when you write this method return ""; } public boolean incrScore(String team) { // A stub -- remove when you write this method return false; } public void display() {

} public static double getAvg() { // A stub -- remove when you write this method return 0.0; } }

Play Soccer Game . Java

package hw5;

// // Modify as you wish to test your code; you will only submit SoccerGame.java.

public class PlaySoccerGames {

public static void main(String[] args) { System.out.println("The average score across all games is: " + SoccerGame.getAvg()); System.out.println(); System.out.println("Information for the first game: "); SoccerGame game1 = new SoccerGame(); game1.display(); System.out.println("The average score across all games is: " + SoccerGame.getAvg()); if (game1.incrScore(game1.getTeam1())) System.out.println(game1.getTeam1() + " scored a goal."); else System.out.println(game1.getTeam1() + " did not score a goal."); game1.display(); System.out.println("The average score across all games is: " + SoccerGame.getAvg()); if (game1.incrScore(game1.getTeam2())) System.out.println(game1.getTeam2() + " scored a goal."); else System.out.println(game1.getTeam2() + " did not score a goal."); game1.display(); System.out.println("The average score across all games is: " + SoccerGame.getAvg()); if (game1.incrScore(game1.getTeam1())) System.out.println(game1.getTeam1() + " scored a goal."); else System.out.println(game1.getTeam1() + " did not score a goal."); game1.display(); System.out.println("The average score across all games is: " + SoccerGame.getAvg()); System.out.println(); System.out.println("Information for the second game: "); SoccerGame game2 = new SoccerGame("Chicago Fire", "Columbus Crew"); game2.display(); System.out.println("The average score across all games is: " + SoccerGame.getAvg()); if (game2.incrScore(game2.getTeam1())) System.out.println(game2.getTeam1() + " scored a goal."); else System.out.println(game2.getTeam1() + " did not score a goal."); game2.display(); System.out.println("The average score across all games is: " + SoccerGame.getAvg()); if (game2.incrScore(game2.getTeam1())) System.out.println(game2.getTeam1() + " scored a goal."); else System.out.println(game2.getTeam1() + " did not score a goal."); game2.display(); System.out.println("The average score across all games is: " + SoccerGame.getAvg()); if (game2.incrScore("Killer Prudence")) System.out.println("Killer Prudence scored a goal."); else System.out.println("Killer Prudence did not score a goal."); game2.display(); System.out.println("The average score across all games is: " + SoccerGame.getAvg()); }

}

image text in transcribed

image text in transcribed

Assignment For this assignment you will write a class SoccerGame to represent a single game of soccer. The class should be saved in a file called SoccerGame.java. I have provided a template that you should download from D2L. The class has the following instance variables * private String teaml - the name of the firs * private String team2 the name of the second team playing in the game * private int team1Score the current score of the first team playing in the game * private int team2Score - the current score of the second team playing in the game * private final int MIN SCORE - a constant representing the minimum score of a game; it is initialized to 0 in the template file * private static int totalGames - the total number of SoccerGame objects in existence; it is initialized to 0 in the template file * private static int totalScore --the total number of points scored by any team in any game; it is initialized to 0 in the template file t team playing in the game You will complete the assignment by writing the following methods for the SoccerGame class 1. public SoccerGame0: A constructor that creates a game with team 1 being "Blaine" and team 2 being "Hamilton". The scores for both teams should be set to MIN_SCORE. The assignment of the values in the object must be done using explicit assignment statements. Do not rely on default values assigned when any variables are created. The method will need to update totalGames 2. public SoccerGame(String t1, String t2): A constructor that creates a game with team 1 being t1 and team 2 being t2. The scores for both teams should be set to MIN SCORE. The assignment of the values in the object must be done using explicit assignment statements. Do not rely on default values assigned when any variables are created. The method will need to update totalGames 3. public String getTeam10: Return the name of team 1 4. public String getTeam20: Return the name of team 2 5. public void displayO: Print the team names and scores to standard output. See the sample display below for examples 6. public boolean incrScore(String team): If team matches the name of one of the teams playing in the current game, then the method should increase the score for that team by 1 and return true. If team does not match either of the names, then the method should not change any scores and return false Remember to compare Strings using a method (e.g. equals or compareTo) rather than using theoperator. The method will need to update totalScore if a valid team name is provided 7. public static double getAvg0: Return the average score of all games in existence. If there are no games that exist, then this will be 0.0. If there is at least one ou need to perform decimal division to game in existence, then it will be the total score of all games divided by the total number of games. Remember that y make this answer correct, which will involve a cast to double. Ask if you're having trouble figuring out how to do that I have provided a driver program (e.g. a main method that uses the SoccerGame class) PlaySoccerGames.java to help you test your code which has been posted to D2L. Note that you cannot assume that the test cases provided there are the only ones the grader will use. Also, please only submit the SoccerGame.java file The following is the output from my completed solution using the PlaySoccerGames.java driver program

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

Transact SQL Cookbook Help For Database Programmers

Authors: Ales Spetic, Jonathan Gennick

1st Edition

1565927567, 978-1565927568

More Books

Students also viewed these Databases questions