Answer:
Here is the Team class.
public class Team { //class name
// private type data members of Team class
private String team_name; //name of the team
private int no_of_wins; //number of team wins
private int no_of_losses; //number of team losses
public String getTeamName() { //accessor to get the name of the team from data field team_name
return team_name;} /return the name of the team
public void setTeamName(String team_name) {//mutator to set the name of the team using data field team_name
this.team_name= team_name;}
/*this keyword is used here because formal parameters and instance variables are same.So it is used to differentiate between local and instance variable. */
public int getTeamWins() {//accessor to get the number of wins from data field no_of_wins
return no_of_wins;}
public void setTeamWins(int no_of_wins) {//mutator to set the team wins using data field no_of_wins
this.no_of_wins = no_of_wins;}
public int getTeamLosses() {//accessor to get the team losses from data field no_of_loses
return no_of_losses;}
public void setTeamLosses(int no_of_losses) {//mutator to set the team losses using data field no_of_loses
this.no_of_losses = no_of_losses;}
public double getWinPercentage() { //formula to compute win percentage
double win_percent; //to hold the value of winning average of team
win_percent =(double)no_of_wins/(no_of_wins+no_of_losses); //computes winning average
return win_percent; }} //returns value of winning percentage
Step-by-step explanation:
Team class has three private data members team_name for the name of the team, no_of_wins to hold the value of the number of wins by the team and no_of_losses hold the value of the number of losses by the team. accessore and mutators are used to access and modify/set the values for each data field. The getWinPercentage() computes the winning percentage by dividing the number of wins to the total number of team wins and losses in order to get the winning average of the team. The result is stored in win_percent. The method then returns the value of win_percent.
The class, main method and output screenshots are attached.