Hi Im having an error when I compile my code Its this constr
Hi, I\'m having an error when I compile my code.
It\'s this: constructor AthleteManagement in class AthleteManagement cannot be applied to given types;
    AthleteManagement athleteRecord1 = new AthleteManagement();
    ^
 required: ArrayList<Athlete>
 found: no arguments
 reason: actual and formal argument lists differ in length
 C:\\Users\\Jake\\OneDrive\\CSE 205 Folder\\Assignment8.java:83: error: cannot find symbol
 int athleteCount = athleteRecord1.countHowManyAthletesHaveMedals(medalType);
 ^
 symbol: method countHowManyAthletesHaveMedals(int)
 location: variable athleteRecord1 of type AthleteManagement
 2 errors
The code:
//Assignment8
import java.io.*;
 import java.util.*;
public class Assignment8
 {
 public static void main (String[] args) throws FileNotFoundException, IOException
 {
 char input1;
 String firstName, lastName, sport;
 int gold, silver, bronze = 0;
 boolean operation = false;
 int operation2 = 0;
 String line;
 String filename;
//Creates a AthleteManagement object. This is used throughout this class.
    AthleteManagement athleteRecord1 = new AthleteManagement();
try
 {
 // print out the menu
 printMenu();
// create a BufferedReader object to read input from a keyboard
 InputStreamReader isr = new InputStreamReader (System.in);
 BufferedReader stdin = new BufferedReader (isr);
do
 {
 System.out.print(\"What action would you like to perform?\ \");
 line = stdin.readLine().trim(); //read a line
 input1 = line.charAt(0);
 input1 = Character.toUpperCase(input1);
if (line.length() == 1) //check if a user entered only one character
 {
 switch (input1)
 {
 case \'A\': //Add Athlete
 try
 {
 System.out.print(\"Please enter the following information of an athlete:\ \");
 System.out.print(\"First Name:\ \");
 firstName = stdin.readLine().trim();
 System.out.print(\"Last Name:\ \");
 lastName = stdin.readLine().trim();
 System.out.print(\"Sport:\ \");
 sport = stdin.readLine().trim();
 System.out.print(\"The number of gold medals\ \");
 gold = Integer.parseInt(stdin.readLine().trim());
 System.out.print(\"The number of silver medals\ \");
 silver = Integer.parseInt(stdin.readLine().trim());
 System.out.print(\"The number of bronze medals\ \");
 bronze = Integer.parseInt(stdin.readLine().trim());
operation = athleteRecord1.addAthlete(firstName,lastName,sport,gold,silver,bronze);
  if (operation == true)
 System.out.print(\"athlete added\ \");
 else
 System.out.print(\"athlete exists\ \");
 }
 /************************************************************************************
  *** Complete the follwing catch statement
 ***********************************************************************************/
  catch(IOException | NumberFormatException exception)
 {
                    System.out.println(\"Exception occured:\" + exception);
 }
 break;
 case \'D\': //Count athletes by medal type
 try
 {
 System.out.print(\"Please enter a medal type, 0 for gold, 1 for silver, 2 for bronze, to count the athletes with such medal:\ \");
 int medalType = Integer.parseInt(stdin.readLine().trim());
 int athleteCount = athleteRecord1.countHowManyAthletesHaveMedals(medalType);
System.out.print(\"The number of athletes with the given medal type: \" + athleteCount + \"\ \");
 }
 catch(IOException | NumberFormatException e)
 {
                    System.out.println(e);
 }
 break;
 case \'E\': //Search by athlete name
 System.out.print(\"Please enter the first and last names of an athlete to search:\ \");
 System.out.print(\"First Name:\ \");
 firstName = stdin.readLine().trim();
 System.out.print(\"Last Name:\ \");
 lastName = stdin.readLine().trim();
 operation2=athleteRecord1.athleteNameExists(firstName, lastName);
if (operation2 > -1)
 System.out.print(\"athlete found\ \");
 else
 System.out.print(\"athlete not found\ \");
 break;
 case \'L\': //List athletes
 System.out.print(athleteRecord1.listAthletes());
 break;
 case \'O\': // Sort by athlete names
 athleteRecord1.sortByAthleteNames();
 System.out.print(\"sorted by athlete names\ \");
 break;
 case \'P\': // Sort by medal counts
 athleteRecord1.sortByMedalCounts();
 System.out.print(\"sorted by medal counts\ \");
 break;
 case \'Q\': //Quit
 break;
 case \'R\': //Remove by athlete names
 System.out.print(\"Please enter the first and last names of an athlete to remove:\ \");
 System.out.print(\"First Name:\ \");
 firstName = stdin.readLine().trim();
 System.out.print(\"Last Name:\ \");
 lastName = stdin.readLine().trim();
 operation=athleteRecord1.removeAthleteByName(firstName, lastName);
if (operation == true)
 System.out.print(\"athlete removed\ \");
 else
 System.out.print(\"athlete not found\ \");
 break;
 case \'T\': //Close AthleteManagement
 athleteRecord1.closeAthleteManagement();
 System.out.print(\"athlete management system closed\ \");
 break;
 case \'U\': //Write Text to a File
 System.out.print(\"Please enter a file name to write:\ \");
 filename = stdin.readLine().trim();
 try
    {
                            FileWriter fw = new FileWriter(filename, operation);
                            System.out.println(\"Please enter a string to write into the file:\");
                            Scanner input = new Scanner(System.in);
                            line = input.nextLine();
                            fw.write(line);
                       }
                            catch(Exception e)
                            {
                                System.out.println(e);
                            }
 break;
 case \'V\': //Read Text from a File
 System.out.print(\"Please enter a file name to read:\ \");
 filename = stdin.readLine().trim();
 BufferedReader br;
                        try
                        {
                        Scanner infile = new Scanner(new FileReader(filename));
                        line = infile.nextLine();
                        System.out.println(\"The first line of the file is:\" + line);
                    }
                    catch(Exception e)
                        {
                        System.out.println(e);
                 }
 break;
 case \'W\': //Serialize AthleteManagement to a File
 System.out.print(\"Please enter a file name to write:\ \");
 filename = stdin.readLine().trim();
    try
        {
                                try(FileOutputStream fileOut = new FileOutputStream(filename))
                                    {
                                        ObjectOutputStream out = new ObjectOutputStream(fileOut);
                                        out.writeObject(athleteRecord1);
                                        out.close();
                                    }
                            }
                        catch(IOException e)
                            {
                                System.out.println(e);
                            }
 break;
 case \'X\': //Deserialize AthleteManagement from a File
 System.out.print(\"Please enter a file name to read:\ \");
 filename = stdin.readLine().trim();
 AthleteManagement athleteRecord = null;
                        try
                            {
                                FileInputStream fileIn = new FileInputStream(filename);
                                ObjectInputStream in = new ObjectInputStream(fileIn);
                                athleteRecord = (AthleteManagement) in.readObject();
                                in.close();
                                fileIn.close();
                            }
                        catch(IOException i)
                            {
                                System.out.println(i);
                                return;
                            }
                        catch(ClassNotFoundException c)
                            {
                                System.out.println(\"AthleteManagement class not found\");
                                System.out.println(c);
                                return;
                            }
                   System.out.println(\"AthleteManagement object...\");
                    System.out.println(athleteRecord.toString());
 break; case \'?\': //Display Menu
 printMenu();
 break;
 default:
 System.out.print(\"Unknown action\ \");
 break;
 }
 }
 else
 {
 System.out.print(\"Unknown action\ \");
 }
 } while (input1 != \'Q\' || line.length() != 1);
 }
 catch (IOException exception)
 {
 System.out.print(\"IO Exception\ \");
 }
 }
/** The method printMenu displays the menu to a user **/
 public static void printMenu()
 {
 System.out.print(\"Choice\\t\\tAction\ \" +
 \"------\\t\\t------\ \" +
 \"A\\t\\tAdd Athlete\ \" +
 \"D\\t\\tCount Athletes for Medal Type\ \" +
 \"E\\t\\tSearch for Athlete Name\ \" +
 \"L\\t\\tList Athletes\ \" +
 \"O\\t\\tSort by Athlete Names\ \" +
 \"P\\t\\tSort by Medal Counts\ \" +
 \"Q\\t\\tQuit\ \" +
 \"R\\t\\tRemove by Athlete Name\ \" +
 \"T\\t\\tClose AthleteManagement\ \" +
 \"U\\t\\tWrite Text to File\ \" +
 \"V\\t\\tRead Text from File\ \" +
 \"W\\t\\tSerialize AthleteManagement to File\ \" +
 \"X\\t\\tDeserialize AthleteManagement from File\ \" +
 \"?\\t\\tDisplay Help\ \ \");
 }
 } // end of Assignment8 class
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
//AthleteManagement.java
import java.util.*;
 import java.io.*;
//AthleteManagement class implements the Serializable interface
 public class AthleteManagement implements Serializable
 {
    private ArrayList<Athlete> athleteList;
    public AthleteManagement(ArrayList<Athlete> athleteList)
    {
    this.athleteList = athleteList;
 }
   int athleteNameExists(String firstName, String lastName)
    {
        for (int i = 0; i < athleteList.size(); i++) {
            Athlete athlete = (Athlete) athleteList.get(i);
            if (firstName.equals(athlete.getFirstName()) && lastName.equals(athlete.getLastName()))
            {
                return i;
            }
        }
        return -1;
    }
   int countHowManyAthleteHaveMedals(int medalType)
    {
        int count = 0;
        for (int i = 0; i < athleteList.size(); i++)
        {
            Athlete athlete = athleteList.get(i);
            if (medalType == 0 && athlete.getGold() > 0)
            {
                count += 1;
            } else if (medalType == 1 && athlete.getSilver() > 0)
            {
                count += 1;
            } else if (medalType == 2 && athlete.getBronze() > 0)
            {
                count += 1;
            }
        }
        return count;
    }
   public boolean addAthlete(String firstName, String lastName, String sport, int gold, int silver, int bronze)
    {
        int result = athleteNameExists(firstName, lastName);
        if (result < 0)
        {
            Athlete athletes = new Athlete(firstName, lastName, sport, gold, silver, bronze);
            athletes.setSport(sport);
            athletes.setFirstName(firstName);
            athletes.setLastName(lastName);
            athletes.setBronze(bronze);
            athletes.setSilver(silver);
            athletes.setGold(gold);
            this.athleteList.add(athletes);
            return true;
        }
        return false;
    }
   public boolean removeAthleteByName(String firstName, String lastName)
    {
        int index = athleteNameExists(firstName, lastName);
        if (index > 0)
        {
            athleteList.remove(index);
            return true;
        }
        return false;
    }
   public void sortByAthleteNames()
    {
        new Sorts().sort(this.athleteList, new AthleteNameComparator());
    }
   public void sortByMedalCounts()
    {
        new Sorts().sort(this.athleteList, (Comparator<Athlete>) new MedalCountComparator());
    }
   public String listAthletes()
    {
        String athletes = \"\ no athlete\ \ \";
        if (athleteList.size() < 0)
            return athletes;
        StringBuilder stb = new StringBuilder();
        for (int i = 0; i < athleteList.size(); i++)
        {
            Athlete althlete = (Athlete) athleteList.get(i);
            stb.append(althlete.toString());
        }
        return stb.toString();
    }
   public void closeAthleteManagement()
    {
        this.athleteList.clear();
    }
 }
//////////////////////////////////////////////////////////////////////////////
//MedalCountComparator.java
import java.util.*;
public class MedalCountComparator implements Comparator<Athlete>
 {
    public int compare(Athlete first, Athlete second)
    {
        //The 1st athlete has more gold medals than the 2nd athlete.
        if (first.getGold() > second.getGold())
           return -1;
        //The 2nd athlete has more gold medals than the 1st athlete.
        else if (first.getGold() < second.getGold())
           return 1;
        //Both athletes gold medals were equal, now its comparing
        //their silver medals to see who has more.
        else
        {
            //The 1st athlete has more silver medals than the 2nd athlete.
            if (first.getSilver() > second.getSilver())
               return -1;
            //The 2nd athlete has more silver medals than the 1st athlete.
            else if (first.getSilver() < second.getSilver())
               return 1;
            //Both athletes silver medals are equal, now its comparing
            //their bronze medals to see who has more.
            else
            {
                //The 1st athlete has more bronze medals than the 2nd athlete
                if (first.getBronze() > second.getBronze())
                   return -1;
                //The 2nd athlete has more bronze medals than the 1st athlete.
                else if (first.getBronze() < second.getBronze())
                   return 1;
                //Both the athletes have the same amount of all medals
                else
                    return 0;
            }
        }
    }
 }
/////////////////////////////////////////////////////////////////////////////////
//Sorts.java
import java.util.*;
 import java.io.*;
public class Sorts
 {
    public static void sort(ArrayList<Athlete> Athletes, Comparator<Athlete> Comparator)
    {
        //Sorts the array that was entered in by the user
        Collections.sort(Athletes, Comparator);
       //Prints the array
        for (int i = 0; i < Athletes.size(); i++)
        {
            System.out.println(Athletes.get(i));
        }
    }
 }
///////////////////////////////////////////////////////////////////////////////////
//AthleteNameComparator.java
import java.util.*;
public class AthleteNameComparator implements Comparator<Athlete>
 {
    public int compare(Athlete first, Athlete second)
    {
        //The 1st athlete has a shorter last name than the 2nd athlete
        if (first.getLastName().compareToIgnoreCase(second.getLastName()) < 0)
           return -1;
        //The 1st athlete has a longer last name than the 2nd athlete
        else if (first.getLastName().compareToIgnoreCase(second.getLastName()) > 0)
           return 1;
        //The 1st athlete has a shorter first name than the 2nd athlete
        else if (first.getFirstName().compareToIgnoreCase(second.getFirstName()) < 0)
           return -1;
        //The 1st athlete has a longer first name than the 2nd athlete
        else if (first.getFirstName().compareToIgnoreCase(second.getFirstName()) < 0)
return 1;
else
           return 0;
    }
 }
///////////////////////////////////////////////////////////////////////////////////////////////
//Athlete.java
import java.util.*;
public class Athlete implements java.io.Serializable
 {
 private String firstName, lastName;
 private String sport;
 private int gold, silver, bronze;
//Constructor to initialize all member variables
 public Athlete(String firstName, String lastName, String sport,
     int bronze, int silver, int gold)
 {
 super();
 firstName = \"?\";
 lastName = \"?\";
 sport = \"?\";
 gold = 0;
 silver = 0;
 bronze = 0;
 }
//Accessor methods
 public String getFirstName()
 {
 return firstName;
 }
public String getLastName()
 {
 return lastName;
 }
public String getSport()
 {
 return sport;
 }
public int getGold()
 {
 return gold;
 }
public int getSilver()
 {
 return silver;
 }
public int getBronze()
 {
 return bronze;
 }
 //Mutator methods
 public void setFirstName(String first)
 {
 firstName = first;
 }
public void setLastName(String last)
 {
 lastName = last;
 }
public void setSport(String someSport)
 {
 sport = someSport;
 }
public void setGold(int count)
 {
 gold = count;
 }
public void setSilver(int count)
 {
 silver = count;
 }
public void setBronze(int count)
 {
 bronze = count;
 }
//toString() method returns a string containg information of an athlete
 public String toString()
 {
 String result = \"Name:\\t\" + lastName + \",\" + firstName + \"\ \"
 + \"Sport:\\t\" + sport + \"\ \"
 + \"Medal Count:\ \"
 + \"Gold: \" + gold + \"\ \"
 + \"Silver: \" + silver + \"\ \"
 + \"Bronze: \" + bronze + \"\ \ \";
 return result;
 }
 }
//////////////////////////////////////////////////////////////////////////////////////////////
Program Description
Class Diagram:
Solution
 Hi In your \"AthleteManagement\" Class, you have defined only one constructor:
 public class AthleteManagement implements Serializable
 {
 private ArrayList<Athlete> athleteList;
// constructor that takes ArrayList of Athlete
 public AthleteManagement(ArrayList<Athlete> athleteList)
 {
 this.athleteList = athleteList;
 }
/* other stuff */
}
So, you can not create AthleteManagement class Object using this line:
    AthleteManagement athleteRecord1 = new AthleteManagement();
Otherwise firt define a constructor that does not take an argument. Like this:
 public class AthleteManagement implements Serializable
 {
 private ArrayList<Athlete> athleteList;
// constructor that does not takes arguments
 public AthleteManagement()
 {
       // add your stuff
 }
// constructor that takes ArrayList of Athlete
 public AthleteManagement(ArrayList<Athlete> athleteList)
 {
 this.athleteList = athleteList;
 }
/* other stuff */
}










