Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a java class that implements the concept of a sprots team(SportsTeam class

ID: 3767841 • Letter: W

Question

Write a java class that implements the concept of a sprots team(SportsTeam class) that has the following attributes: Mascot, City, Wins, and Losses. The constructor must initialize Mascot and City attributes. Getter and Setter methods are required for all four attributes.

In the test program(TestSportsTeam.java), create and array of 4 sports team objects with the following arrangement of objects.

1) object team1: Mascot="Falcons", City="Atlanta"

2) object team2:  Mascot="Bucs", City="Tampa Bay"

2) object team2:  Mascot="Saints", City="New Orleans"

2) object team2:  Mascot="Panthers", City="Carolina"

For each object, randomly assign a value (no greater than 16) to attributes Wins. Then set the Losses attribute to be equal to 16-win. Next, display header witht the following format( City Mascot Wins Losses WinPct) as shown below. Below the header, display (printout) the team that has the most wins and the fewest wins. Compute the win points as follows: WinPct=Wins/(Wins+Losses). Sample output is:

City Mascot Wins Losses WinPct

Atlanta Falcons 4 12 0.25

New Orleans Saints 13 3 0.82

Explanation / Answer

Please find the required solution:

import java.util.Random;

public class TestSportsTeam {
   public static void main(String[] args) {
       // declare and initialize the state an array of Sports team of size four
       SportsTeam[] sportsTeam = new SportsTeam[4];
       sportsTeam[0] = new SportsTeam("Falcons", "Atlanta");
       sportsTeam[1] = new SportsTeam("Bucs", "Tampa Bay");
       sportsTeam[2] = new SportsTeam("Saints", "New Orleans");
       sportsTeam[3] = new SportsTeam("Panthers", "Carolina");

       int min = 0, minIndex = 0, max = 0, maxIndex = 0;
       // initializes and losses
       Random rdm = new Random();
       for (int i = 0; i < 4; i++) {
           sportsTeam[i].setWins(1 + rdm.nextInt(16));
           sportsTeam[i].setLoses(16 - sportsTeam[i].getWins());
           if (min > sportsTeam[i].getWins()) {
               min = sportsTeam[i].getWins();
               minIndex = i;
           }
           if (max < sportsTeam[i].getWins()) {
               max = sportsTeam[i].getWins();
               maxIndex = i;
           }
       }
       System.out.println(sportsTeam[minIndex]
               + " "
               + (double) sportsTeam[minIndex].getWins()
               / (sportsTeam[minIndex].getWins() + sportsTeam[minIndex]
                       .getLoses()));
       System.out.println(sportsTeam[maxIndex]
               + " "
               + (double) sportsTeam[maxIndex].getWins()
               / (sportsTeam[maxIndex].getWins() + sportsTeam[maxIndex]
                       .getLoses()));

   }// end of main class
}// test class

class SportsTeam {
   String moscot;
   String city;
   int wins;
   int loses;

   // 2- argument constructor Initializes the moscot and city of sports team
   public SportsTeam(String moscot, String city) {
       super();
       this.moscot = moscot;
       this.city = city;
   }

   // getter and setter methods
   public String getMoscot() {
       return moscot;
   }

   public void setMoscot(String moscot) {
       this.moscot = moscot;
   }

   public String getCity() {
       return city;
   }

   public void setCity(String city) {
       this.city = city;
   }

   public int getWins() {
       return wins;
   }

   public void setWins(int wins) {
       this.wins = wins;
   }

   public int getLoses() {
       return loses;
   }

   public void setLoses(int loses) {
       this.loses = loses;
   }

   @Override
   public String toString() {
       return city + " " + moscot + " " + wins + " " + loses + " ";
   }

}

Sample output:

Atlanta   Falcons   7   9       0.4375
New Orleans   Saints   10   6       0.625

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote