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
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;
}
}
Comments
Leave a comment