Answer to Question #301792 in Java | JSP | JSF for sandyJay

Question #301792

create a Java application which will Simulate a Soccer game Match and display the results.

Question 1 – Team.

Create a class called Team that will be used for creating team objects, the class must have the following data members and methods:

Data Members:

-Name,the name of the team.

-HomeGround, the name of the Home stadium of the team.

-Goals, the number of goals that the team scores during the match Choose appropriate types for the data members.

Methods:

-A default constructor which will initialize all data members to proper initial values.

-An overloaded constructor which receives two arguments; a team name and home ground name and it should also initialize the goals to a proper initial value.

scoreGoals(), since a team can score 0 to 4 goals, this helper method must assign the Goals data member to a random number in that range.

-getName(), getHomeGround(), getGoals(), create get methods for each data member


1
Expert's answer
2022-02-23T14:46:29-0500
import java.util.Random;

public class Team {
    private String name;
    private String homeGround;
    private int goals;

    public Team() {
        this("Unknown", "Unknown");
    }

    public Team(String name, String homeGround) {
        this.name = name;
        this.homeGround = homeGround;
        goals = 0;
    }

    public void scoreGoals() {
        goals = new Random().nextInt(5);
    }

    public String getName() {
        return name;
    }

    public String getHomeGround() {
        return homeGround;
    }

    public int getGoals() {
        return goals;
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS