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

I need help creating AthleteManagement class which deals with the given Athlete

ID: 3929659 • Letter: I

Question

I need help creating AthleteManagement class which deals with the given Athlete class, Sorts class, AthleteNameComparator class, and MedalCountComparator class.

AthleteManagement

The AthleteManagement class has a list of Athlete objects that can be organized at the athlete management system. The athlete management system will be a fully encapsulated object. The AthleteManagement class implements the Serializable interface.
It has the following attributes:

The following public methods should be provided to interact with the athlete management system:

No input/output should occur in the athlete management system. User interaction should be handled only by the driver class.

You may add other methods to the class in order to make your life easier.

Athlete class

Sorts class

public class Sorts

{  

   public static void sort(ArrayList<Athlete> sort1, Comparator<Athlete> AComparator)

   {

          Collections.sort(sort1, AComparator); //sorts the array that was given as input

System.out.println("After sorting, this is the array: ");

for (int i = 0; i < sort1.size(); i++)

{

System.out.println(sort1.get(i)); // for loop to print the array

}

   }

}

AthleteNameComparator class

public class AthleteNameComparator implements Comparator<Athlete>

{

   public int compare(Athlete first, Athlete second)  

   {

       if(first.getLastName().compareToIgnoreCase(second.getLastName()) < 0)

           return -1;

       else if(first.getLastName().compareToIgnoreCase(second.getLastName()) > 0)

           return 1;

       else

           return 0;

   }

}

MedalCountComparator class

public class MedalCountComparator implements Comparator <Athlete>

{

   public int compare(Athlete first, Athlete second)  

   {

       if(first.getGold() > second.getGold())

           return -1;   

       else if(first.getGold() < second.getGold())

           return 1;

       else

       {

           if(first.getSilver() > second.getSilver())

               return -1;

           else if(first.getSilver() < second.getSilver())

               return 1;

           else

           {

               if(first.getBronze() > second.getBronze())

                   return -1;   

               else if(first.getBronze() < second.getBronze())

                   return 1;

               else

                   return 0;

           }

       }

   }

}

Attribute name Attribute type Description athleteList ArrayList or Vector A list of Athlete objects in the athlete management system

Explanation / Answer

Please let me know if you need more information:-

===============================================

AthleteManagement .java

===============================================

import java.util.ArrayList;
import java.util.Comparator;

public class AthleteManagement {
   private ArrayList<Athlete> athleteList;

   public AthleteManagement(ArrayList<Athlete> athleteList) {
       this.athleteList = athleteList;
   }

   protected int athleteNameExists(String firstName, String lastName) {

       for (int i = 0; i < athleteList.size(); i++) {
           Athlete al_tmp = (Athlete) athleteList.get(i);
           if (firstName.equals(al_tmp.getFirstName())
                   && lastName.equals(al_tmp.getLastName())) {
               return i;
           }
       }
       return -1;

   }

   protected int countHowManyAthleteHaveMedals(int medalType) {

       int count = 0;
       for (int i = 0; i < athleteList.size(); i++) {
           Athlete al_tmp = (Athlete) athleteList.get(i);
           if (medalType == 0 && al_tmp.getGold() > 0) {
               count += 1;
           } else if (medalType == 1 && al_tmp.getSilver() > 0) {
               count += 1;
           } else if (medalType == 2 && al_tmp.getBronze() > 0) {
               count += 1;
           }
       }
       return count;

   }

   protected boolean addAthlete(String firstName, String lastName,
           String sport, int gold, int silver, int bronze) {
       if (athleteNameExists(firstName, lastName) < 0) {
           Athlete al_tmp = new Athlete();
           al_tmp.setFirstName(firstName);
           al_tmp.setLastName(lastName);
           al_tmp.setSport(sport);
           al_tmp.setGold(gold);
           al_tmp.setBronze(bronze);
           al_tmp.setSilver(silver);
           this.athleteList.add(al_tmp);
           return true;
       }
       return false;

   }

   protected boolean removeAthleteByName(String firstName, String lastName) {
       int index = athleteNameExists(firstName, lastName);
       if (index > 0) {
           athleteList.remove(index);
           return true;
       }
       return false;
   }

   protected void sortByAthleteNames() {
       new Sorts().sort(athleteList, new AthleteNameComparator());
   }

   protected void sortByMedalCounts() {
       new Sorts().sort(athleteList,
               (Comparator<Athlete>) new MedalCountComparator());
   }

   protected String listAthletes() {
       String tmp = " no athlete ";
       if (athleteList.size() < 0)
           return tmp;
       StringBuilder stb = new StringBuilder();
       for (int i = 0; i < athleteList.size(); i++) {
           Athlete al_tmp = (Athlete) athleteList.get(i);
           stb.append(al_tmp.toString());
       }
       return stb.toString();
   }

   protected void closeAthleteManagement() {
       athleteList.clear();
   }
}

=================================================

Thanks

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