Question

You are building a system to keep track of matches played by a soccer team. You...

You are building a system to keep track of matches played by a soccer team. You need to create a class to represent your matches. Call this class Soccer Match. The class will have the following data fields and methods:

• A Date data field called startTime to register the date and time for the start of the match.

• A Date data field called endTime to register the date and time for the end of the match.

A String data field called location for the venue of the match

A String data field called home for the home team name.

A String data field called visitor for the visitor's team name.

An array of a Player class (to be designed also) called home Players of size 11 for the home team players (assume no substitutions).

An array of Player class called visitorPlayers of size 11 for the visiting team players.

An array of Goal class (to be designed also) data field called home Goals for the home team goals (size 10).

An array of Goal class data field called visitor Goals for the visitor team goals (size 10).

A no-arg constructor to create a new match.

A constructor that creates a new match on a specific date and time between two teams.

An addHomePlayer(Player p) method that adds a player to the home team.

An addVisitorPlayer(Player p) method that adds a player to the visitor team.

A getWinner() method that returns the name of the winner. In case of a tie it returns the word “tie” •

An addHomeGoal(Goal g) that adds a goal for the home team.

An addVisitor Goal(Goal g) that adds a goal for the visitor team. • •

A getHome Goals() method to get a list of the goals for the home team. AgetVisitorGoals() method to get the goals of the visitor team. Create a Player class for the players with the following data fields and methods: • • • • •

A String field called name for the name of the player.

An int called goals to track the lifetime goals of the player.

A String field called team for the name of team of the player.

A no-arg constructor to create a new player. Getters and setters for all the data fields. Create a Goal class to track goals with the following data fields and methods: •

An int field call minute for the minute at which the goal is scored. •

A Player fields called player for the player scoring the goal. Contructors, getters and setters for this class.

Draw the UML diagram for the three classes and then implement the classes. Write a test program for a simulated soccer match.

Need the answer in java please

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Program Files

Player.java

//player class
public class Player {
//declaring variables
private String name;
private int goals;
private String team;
//no-args constructor
Player(){};
public String getName() {
return name;
}
//setter for name
public void setName(String name) {
this.name = name;
}
//getter for goals
public int getGoals() {
return goals;
}
//setter for goals
public void setGoals(int goals){
this.goals = goals;
}
//getters and setters for team
public String getTeam() {
return team;
}
public void setTeam(String team){
this.team = team;
}

}

Goal.java

import java.util.Date;

//class for the goals
public class Goal {
  
//defining the attributes
private Date minute;
private Player player;
//no args constructor
Goal(){};
//secondary constructor
Goal(Date minute, Player player){
this.minute = minute;
this.player = player;
}
//setters and getters for both minute and player
public void setMinute(Date minute) {
this.minute = minute;
}
public Date getMinute() {
return minute;
}
public void setPlayer(Player player) {
this.player = player;
}
public Player getPlayer() {
return player;
}
}

soccerMatch.java

import java.util.Date;

/* soccer match class */

public class soccerMatch {

//setting attributes
Date startTime;
Date endTime;
String location;
String home = "home";
String visitor = "visitor";
private Player[] homePlayers = new Player[11];
private Player[] visitorPlayers = new Player[11];
private Goal[] homeGoals = new Goal[10];
private Goal[] visitorGoals = new Goal[10];

//no-args constructor
soccerMatch() {};

//secondary constructor
soccerMatch( Date startTime, Player[] homePlayers, Player[] visitorPlayers){
this.startTime = startTime;
this.homePlayers = homePlayers;
this.visitorPlayers = visitorPlayers;
}

//adds necessary for private attributes
public void addHomePlayer(Player player) {
for(Player n: homePlayers) {
if(n==null) {
n = player;
break;
}
}
player.setTeam("home");
}
  
public void addVisitorPlayer(Player player){
for(Player n: visitorPlayers) {
if(n == null) {
n = player;
break;
}
}
player.setTeam("visitor");
}

//finds which team has more goals listed
public String getWinner() {
int countH = 0;
for(Goal g : homeGoals) {
if (g != null) {
++countH;
}
}
int countV = 0;
for(Goal g : visitorGoals) {
if (g != null) {
++countV;
}
}
if(countH > countV) {
return "home";
}
else if(countV > countH) {
return "visitor";
}
else {
return "tie";
}
}

//used to add a goal to home
public void addHomeGoal(Goal goal) {
for(int g = 0;g<10;g++) {
if(this.homeGoals[g]==null) {
this.homeGoals[g] = goal;
break;
}
  
}
}

//adds visitor goal
public void addVisitorGoal(Goal goal) {
for(int g = 0;g<10;g++) {
if(this.visitorGoals[g]==null) {
this.visitorGoals[g] = goal;
break;
}
  
}
}

//getters for the goals for each team
public Goal[] getHomeGoals() {
return homeGoals;
}
  
public Goal[] getVisitorGoals() {
return visitorGoals;
}
}

Game.java

import java.util.Date;

//class that is an example of how a game would be played using these classes
public class Game {
public static void main(String[] args) {
  
//creating the players and naming them
Player matt = new Player();
matt.setName("Matt");
Player mike = new Player();
mike.setName("Mike");
  
Player mark = new Player();
mark.setName("Mark");
  
Player jonah = new Player();
jonah.setName("Jonah");
  
Player james = new Player();
james.setName("James");
  
Player noah = new Player();
noah.setName("Noah");
//making a soccer game
soccerMatch game = new soccerMatch();
//distributing the players
game.addVisitorPlayer(matt);
game.addVisitorPlayer(mike);
game.addVisitorPlayer(mark);
game.addHomePlayer(jonah);
game.addHomePlayer(james);
game.addHomePlayer(noah);
//playing the game
score(game, "home", noah, new Date());
score(game, "home", james, new Date());
score(game, "home", noah, new Date());
score(game, "home", jonah, new Date());
score(game, "visitor", mike, new Date());
score(game, "home", jonah, new Date());
score(game, "visitor", matt, new Date());
score(game, "visitor", mark, new Date());
score(game, "visitor", mark, new Date());
score(game, "home", noah, new Date());
score(game, "visitor", mike, new Date());
score(game, "home", jonah, new Date());
score(game, "home", jonah, new Date());
score(game, "home", jonah, new Date());
score(game, "visitor", matt, new Date());
score(game, "home", james, new Date());
score(game, "visitor", mark, new Date());
//formatting and displaying the home team goals
System.out.println("-----");
System.out.println("HOME TEAM");
for(int i = 0; i< game.getHomeGoals().length;i++) {
if(game.getHomeGoals()[i] != null) {
System.out.print("goal number " + (i+1) + " was scored at " + game.getHomeGoals()[i].getMinute());
System.out.println(" by " + game.getHomeGoals()[i].getPlayer().getName() + " for the "+ game.getHomeGoals()[i].getPlayer().getTeam() + " team." );
System.out.println("*****");
}
else {
break;
}
}
//formatting and displaying the visitor team goals
System.out.println("-----");
System.out.println("VISITOR TEAM");
for(int n = 0; n< game.getVisitorGoals().length;n++) {
if(game.getVisitorGoals()[n] != null) {
System.out.print("goal number " + (n+1) + " was scored at " + game.getVisitorGoals()[n].getMinute());
System.out.println(" by " + game.getVisitorGoals()[n].getPlayer().getName() + " for the "+ game.getVisitorGoals()[n].getPlayer().getTeam() + " team." );
System.out.println("*****");
}
else {
break;
}
}
System.out.println("-----");
System.out.println("AAAAND the Winner is...");
System.out.println("The " + game.getWinner() + " team!!!");
}
//score method which decides who to give the point to, adds the goal with the player and time to the list, and adds a goal to the player
//and correctly announcing the goal to the world
public static void score( soccerMatch game, String team, Player player,Date time) {
  
if(team == "home") {
System.out.println("GOOOOOOOOOOOOOOOAL FOR THE HOME TEAM!!!");
game.addHomeGoal(new Goal(time, player));
player.setGoals(player.getGoals()+1);
}
else if(team == "visitor") {
System.out.println("GOOOOOOOOOOOOOOOAL FOR THE OTHER GUYS!!!");
game.addVisitorGoal(new Goal(time, player));
player.setGoals(player.getGoals()+1);
}
}
}

output

 java -classpath .:/run_dir/junit-4.12.jar:target/dependency/* Main
GOOOOOOOOOOOOOOOAL FOR THE HOME TEAM!!!
GOOOOOOOOOOOOOOOAL FOR THE HOME TEAM!!!
GOOOOOOOOOOOOOOOAL FOR THE HOME TEAM!!!
GOOOOOOOOOOOOOOOAL FOR THE HOME TEAM!!!
GOOOOOOOOOOOOOOOAL FOR THE OTHER GUYS!!!
GOOOOOOOOOOOOOOOAL FOR THE HOME TEAM!!!
GOOOOOOOOOOOOOOOAL FOR THE OTHER GUYS!!!
GOOOOOOOOOOOOOOOAL FOR THE OTHER GUYS!!!
GOOOOOOOOOOOOOOOAL FOR THE OTHER GUYS!!!
GOOOOOOOOOOOOOOOAL FOR THE HOME TEAM!!!
GOOOOOOOOOOOOOOOAL FOR THE OTHER GUYS!!!
GOOOOOOOOOOOOOOOAL FOR THE HOME TEAM!!!
GOOOOOOOOOOOOOOOAL FOR THE HOME TEAM!!!
GOOOOOOOOOOOOOOOAL FOR THE HOME TEAM!!!
GOOOOOOOOOOOOOOOAL FOR THE OTHER GUYS!!!
GOOOOOOOOOOOOOOOAL FOR THE HOME TEAM!!!
GOOOOOOOOOOOOOOOAL FOR THE OTHER GUYS!!!
-----
HOME TEAM
goal number 1 was scored at Mon Mar 23 16:42:49 UTC 2020 by Noah for thehome team.
*****
goal number 2 was scored at Mon Mar 23 16:42:49 UTC 2020 by James for the home team.
*****
goal number 3 was scored at Mon Mar 23 16:42:49 UTC 2020 by Noah for thehome team.
*****
goal number 4 was scored at Mon Mar 23 16:42:49 UTC 2020 by Jonah for the home team.
*****
goal number 5 was scored at Mon Mar 23 16:42:49 UTC 2020 by Jonah for the home team.
*****
goal number 6 was scored at Mon Mar 23 16:42:49 UTC 2020 by Noah for thehome team.
*****
goal number 7 was scored at Mon Mar 23 16:42:49 UTC 2020 by Jonah for the home team.
*****
goal number 8 was scored at Mon Mar 23 16:42:49 UTC 2020 by Jonah for the home team.
*****
goal number 9 was scored at Mon Mar 23 16:42:49 UTC 2020 by Jonah for the home team.
*****
goal number 10 was scored at Mon Mar 23 16:42:49 UTC 2020 by James for the home team.
*****
-----
VISITOR TEAM
goal number 1 was scored at Mon Mar 23 16:42:49 UTC 2020 by Mike for thevisitor team.
*****
goal number 2 was scored at Mon Mar 23 16:42:49 UTC 2020 by Matt for thevisitor team.
*****
goal number 3 was scored at Mon Mar 23 16:42:49 UTC 2020 by Mark for thevisitor team.
*****
goal number 4 was scored at Mon Mar 23 16:42:49 UTC 2020 by Mark for thevisitor team.
*****
goal number 5 was scored at Mon Mar 23 16:42:49 UTC 2020 by Mike for thevisitor team.
*****
goal number 6 was scored at Mon Mar 23 16:42:49 UTC 2020 by Matt for thevisitor team.
*****
goal number 7 was scored at Mon Mar 23 16:42:49 UTC 2020 by Mark for thevisitor team.
*****
-----
AAAAND the Winner is...
The home team!!!

Hope this helps!

Please let me know if any changes needed.

Thank you!

Add a comment
Know the answer?
Add Answer to:
You are building a system to keep track of matches played by a soccer team. You...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Create a class Team to hold data about a college sports team. The Team class holds...

    Create a class Team to hold data about a college sports team. The Team class holds data fields for college name (such as Hampton College), sport (such as Soccer), and team name (such as Tigers). Include a constructor that takes parameters for each field, and get methods that return the values of the fields. Also include a public final static String named MOTTO and initialize it to Sportsmanship! Save the class in Team.java. Create a UML class diagram as well.

  • This problem will create a monthly ledger for a user to keep track of monthly bills....

    This problem will create a monthly ledger for a user to keep track of monthly bills.  The program will start by asking the user for an amount of monthly bills to pay.  Design of this solution will involve four classes, some may involve the use of previously written code: Class Design:  OurDate class – update your previously written OurDate class to include a toString() method. Be certain that you still have methods that will setDayFromUser(), setMonthFromUser() and...

  • Design a class called Building. The class should keep the following information in the fields: String...

    Design a class called Building. The class should keep the following information in the fields: String address double property_value create several constructors including copy constructor , create accessor and mutator methods        Part 2 (50 points) Define interface Taxable which has one method getPropertyTax() Design a class called Private_Property that extends Building and implements Taxable It should have the following field : double value_of_improvements Create a constructor for this class to include newly added fields. The tax for the private property...

  • Write a class called Player that has four data members: a string for the player's name,...

    Write a class called Player that has four data members: a string for the player's name, and an int for each of these stats: points, rebounds and assists. The class should have a default constructor that initializes the name to the empty string ("") and initializes each of the stats to -1. It should also have a constructor that takes four parameters and uses them to initialize the data members. It should have get methods for each data member. It...

  • You are to write a banking application in c# that keeps track of bank accounts. It will consist of three classes, Account, Bank and BankTest. The Account class is used to represent a savings account i...

    You are to write a banking application in c# that keeps track of bank accounts. It will consist of three classes, Account, Bank and BankTest. The Account class is used to represent a savings account in a bank. The class must have the following instance variables: a String called accountID                       a String called accountName a two-dimensional integer array called deposits (each row represents deposits made in a week). At this point it should not be given any initial value. Each...

  • In C Program This program will store the roster and rating information for a soccer team. There w...

    In C Program This program will store the roster and rating information for a soccer team. There will be 3 pieces of information about each player: Name: string, 1-100 characters (nickname or first name only, NO SPACES) Jersey Number: integer, 1-99 (these must be unique) Rating: double, 0.0-100.0 You must create a struct called "playData" to hold all the information defined above for a single player. You must use an array of your structs to to store this information. You...

  • First you will need to write three classes: Game Shoe Assignment within each class you will...

    First you will need to write three classes: Game Shoe Assignment within each class you will add two fields and a constructor. For Game you will need to keep track of the name of the game (String) and the number of players (int). The constructor will be in the order (String, int). For Shoe you will need the shoe size (double) and the brand (String). The constructor will be in the order (double, String). For Assignment you will need the...

  • Java 7.17 Clone of LAB*: Program: Soccer team roster This program will store roster and rating...

    Java 7.17 Clone of LAB*: Program: Soccer team roster This program will store roster and rating information for a soccer team. Coaches rate players during tryouts to ensure a balanced team. (1) Prompt the user to input five pairs of numbers: A player's jersey number (0-99, but this is NOT enforced by the program nor tested) and the player's rating (1-9, not enforced like jersey numbers). Store the jersey numbers in one int array and the ratings in another int...

  • Hello, In need of help with this Java pa homework. Thank you! 2. Create a normal...

    Hello, In need of help with this Java pa homework. Thank you! 2. Create a normal (POJo, JavaBean) class to represent, i. e. model, varieties of green beans (also known as string beans or snap beans). Following the steps shown in "Assignment: Tutorial on Creating Classes in IntelliJ", create the class in a file of its own in the same package as class Main. Name the class an appropriate name. The class must have (a) private field variables of appropriate...

  • Write a class called Student. The specification for a Student is: Three Instance fields name -...

    Write a class called Student. The specification for a Student is: Three Instance fields name - a String of the student's full name totalQuizScore - double numQuizesTaken - int Constructor Default construtor that sets the instance fields to a default value Parameterized constructor that sets the name instance field to a parameter value and set the other instance fields to a default value. Methods setName - sets or changes the student name by taking in a parameter getName - returns...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT