Answer to Question #305135 in Java | JSP | JSF for Nkulee

Question #305135

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-03-03T09:59:03-0500
package com.task;

import java.util.Random;

public class Team {

    private String name;
    private String homeGround;

    public String getName() {
        return name;
    }

    public String getHomeGround() {
        return homeGround;
    }

    public Integer getGoals() {
        return goals;
    }

    private Integer goals;

    public Team() {
        name = "Team Name";
        homeGround = "Stadium Name";
        goals = 0;
    }

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

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

}

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