Answer to Question #307812 in Java | JSP | JSF for mlu

Question #307812

Create a class called Match that will have team the class must have the following data members and methods:









Data Members:





• This class has two data members named HomeTeam and VisitorTeam which are of type Team, they will store that two teams that will play the Match.





Methods:





• This class doesn’t have a default constructor, it only has one constructor which receives two Team object that will be assigned to HomeTeam and VisitorTeam.





• setTeams(),which receives two Team object that will be assigned to HomeTeam and VisitorTeam.





• playMatch(), simulates match play by calling the scoreGoals methods of each team.





• getPlayGound(), returns the ground of play which is the HomeGound of the HomeTeam.





• isDrawMatch(), will return true if the Match is a draw and false if there is a winner. The match is a draw if the goals of the teams are equal.





• getWinner(), returns the team which won the match, a team wins if its goals is higher than the goals of the other team.









1
Expert's answer
2022-03-10T07:15:19-0500
class Match {
	private Team homeTeam;
	private Team visitorTeam;


	public Match(Team homeTeam, Team visitorTeam) {
		setTeams(homeTeam, visitorTeam);
	}


	public void setTeams(Team homeTeam, Team visitorTeam) {
		this.homeTeam = homeTeam;
		this.visitorTeam = visitorTeam;
	}


	public void playMatch() {
		homeTeam.scoreGoals();
		visitorTeam.scoreGoals();
	}


	public String getPlayGround() {
		return homeTeam.getHomeGround();
	}


	public boolean isDrawMatch() {
		return homeTeam.getGoals() == visitorTeam.getGoals();
	}


	public Team getWinner() {
		return homeTeam.getGoals() > visitorTeam.getGoals() ? homeTeam
				: visitorTeam.getGoals() > homeTeam.getGoals() ? visitorTeam : null;
	}


	public Team getLoser() {
		return homeTeam.getGoals() > visitorTeam.getGoals() ? visitorTeam
				: visitorTeam.getGoals() > homeTeam.getGoals() ? homeTeam : null;
	}


}

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