Question

**Only need the bold answered Implement the Athlete, Swimmer, Runner, and AthleteRoster classes below. Each class...

**Only need the bold answered

Implement the Athlete, Swimmer, Runner, and AthleteRoster classes below. Each class must be in separate file. Draw an UML diagram with the inheritance relationship of the classes.

1. The Athlete class
a. All class variables of the Athlete class must be private.

b.is a class with a single constructor: Athlete(String lName, String fName, int birthYear, int birthMonth, int birthDay, char gender). All arguments of the constructor should be stored as class variables. There should only be getter methods for first and last name variables. There should be no getters or setters for birthYear, birthMonth, birthDay.

c. Getter and setter methods for the gender of the athlete. The method setGender accepts a character and store it as a class variable. Characters 'm', 'M' denotes male, 'f' or 'F' denotes male or female. Any other char will be treated as undeclared. The method getGender return either the word "male" or "female" or “undeclared”.

  1. The method computeAge() takes no arguments and returns the athletes computed age (as of today's date) as a string of the form "X years, Y months and Z days". Hint: Use the LocalDate and Period classes.

    i. e.g. "21 years, 2 months and 3 days". ii. e.g. "21 years and 3 days".

    iii. e.g. "21 years and 2 months". iv. e.g. "21 years".

    v. e.g. "2 months and 3 days".

  2. The method public long daysSinceBirth() takes no arguments and returns a long which is the number of days since the athlete’s date of birth to the current day. Hint: Use the LocalDate and ChronoUnit classes.

  3. The toString method returns a string comprised of the results ofgetFname, getLName and computeAge. E.g.

    i. “Bunny Bugs is 19 years and 1 day old”

  4. The equals method returns true if the name and date of birth of this athlete and the compared other athlete are the same, otherwise return false.

2. The Swimmer class
a. All class variables of the Swimmer class must be private.

  1. inherits from the Athlete class and has a single constructor,

    Swimmer(String lName, String fName, int birthYear, int birthMonth, int birthDay, char gender, String team). There should be a class variable for team. There should be a getter method for team.

  2. The Swimmer class stores swim events for the swimmer. There should be a class variable for events. A swimmer participates in one or more of these events. The addEvent method is oveloadedand either adds a single event for the swimmer public boolean addEvent(String singleEvent) or adds a group of events for the swimmer public boolean addEvent(ArrayList multiEvents). Each event is of type String. Duplicate events are not stored and return false if duplicate found.

  3. There should be a getter method that returns the class variable events.

  4. The overridden toString method returns a string comprised of the concatenation of the parent’s toString return plus " and is a swimmer for team: XXXXX in the following events: YYYYY; ZZZZZZ." E.g.

    i. “Missy Franklin is 24 years and 4 months old and is a swimmer for team: Colorado Stars. She participates in the following events: [100m freestyle, 100m backstroke, 50m backstroke]”

3. The Runner class
a. All class variables of the Runner class must be private.

  1. inherits from the Athlete class and has a single constructor,

    Runner(String lName, String fName, int birthYear, int birthMonth, int birthDay, char gender, String country). There should be a class variable for country. There should be a getter method for country.

  2. The Runner class stores race events for the runner. There should be a class variable for events. Each event is a Distance. The list of valid events is given below:
    M100, M200, M400, M3000, M5000, M10000. A runner participates inone or more of these events. The addEvent method is oveloadedand either adds a single event for the runner public boolean addEvent(String singleEvent) or adds a group of events for the runner public boolean addEvent(ArrayList multiEvents). Each event is of type String. Duplicate events are not stored and return false if duplicate found.

  1. There should be a getter method that returns the class variable events.

  2. The toString method returns a String in the form: " AAA BBBB is XX years, YY months and ZZ days. He is a citizen of CCCCCCC and is a DDDDDDDD who participates in these events: [MJ00, MK00, ML00]”. If she does not participate in M3000 or M5000 or M10000 then she is a sprinter. If she does not participate in M100 or M200 or M400 then she is a long-distance runner. Otherwise she is a super athlete. E.g.

    i. “Bunny Bugs is 19 years and 1 day old. His is a citizen of USA and is a long-distance runner who participates in these events: [M10000]”

4. The AthleteRoster class
a. All class variables of the AthleteRoster class must be private.

  1. Does not inherits from the Athlete class. The AthleteRoster class has a single constructor, AthleteRoster(String semster, int year). There should be class variables for semester and year. There should be getter methods for semester and year.

  2. The AthleteRoster class has only one method for adding Athlete to the roster, by using the boolean addAthlete(Athlete a)method. The method returns true if the athlete was added successfully, it returns false if the athlete object already exists in the roster and therefore was not added.

  3. Your AthleteRoster class will have only one class level data structure, an ArrayList, for storing athlete objects.

  4. The String allAthletesOrderedByLastName() method returns a string object with of all the names of the athletes (Swimmers, Runners, etc.) in ascending order of last names(a-z).

  5. The String allAthletesOrderedByAge() method returns a string object with of all the names of the athletes (Swimmers, Runners, etc.) in descending order of age(100-0).

  6. The String allRunnersOrderedByNumberOfEvents() method returns a string object with of all the names of the Runners only in ascending order of number of events they participate in (0-100).

Complete the code before the due date. Submission of the completed eclipse project is via github link posted on the class page. Add your UML drawing to the github repo. ________________________________________________________________________ Example output:

__________Example from AthleteDriver shown below

Gender is undeclared
Gender is female
Gender is male
ComputeAge method says 19 years and 4 days
First name is : Duck

DaysSinceBirth method says 6943 days Last name is : Daffy
Output of our toString correct?:
Duck Daffy is 19 years and 4 days old =======================================

Did we add M10000 successfully?: true
Did we unsuccessfully try to add M10000 again?: false
Did we successfully add multiple events?: true
Did we unsuccessfully try to add multiple events?: false
How many events does Bugs participate in?: 3
Gender is male
Output of our toString correct?:
Bunny Bugs is 19 years and 3 days old. His is a citizen of USA and is a super athlete who participates in these events: [M10000, M100, M3000] =======================================

0 0
Add a comment Improve this question Transcribed image text
Answer #1

//Athlete.java

import java.time.LocalDate;

import java.time.Period;

import java.time.temporal.ChronoUnit;

public class Athlete {

      

       // private class variables

       private String lName;

       private String fName;

       private int birthYear;

       private int birthMonth;

       private int birthDay;

       private char gender;

      

       // constructor to initialize the variables of the class

       public Athlete(String lName, String fName, int birthYear, int birthMonth, int birthDay, char gender)

       {

             this.lName = lName;

             this.fName = fName;

             this.birthDay = birthDay;

             this.birthMonth = birthMonth;

             this.birthYear = birthYear;

             this.gender = gender;

       }

      

       // method to return the first name

       public String getFName()

       {

             return fName;

       }

      

       // method to return the last name

       public String getLName()

       {

             return lName;

       }

      

       // method to return the gender

       public String getGender()

       {

             if(gender == 'm' || gender == 'M')

                    return "male";

             else if(gender == 'f' || gender == 'F')

                    return "female";

             else

                    return "undeclared";

       }

      

       // method to set the first name

       public void setFirstname(String fName)

       {

             this.fName = fName;

       }

      

       // method to set the last name

       public void setLastname(String lName)

       {

             this.lName = lName;

       }

      

       // method to set the gender

       public void setGender(char gender)

       {

             this.gender = gender;

       }

      

       // method to compute and return the age

       public String computeAge()

       {

             LocalDate currentDate = LocalDate.now();

             LocalDate birthDate = LocalDate.of(birthYear, birthMonth, birthDay);

             Period period = Period.between(birthDate, currentDate);

            

             int years = period.getYears();

             int months = period.getMonths();

             int days = period.getDays();

            

             if(years > 0)

             {     

                    if(months > 0)

                    {

                           if(days > 0)

                                 return years+" years, "+months+" months and "+days+" days";

                           else

                                 return years+" years and "+months+" months ";

                    }else

                    {

                           if(days > 0)

                                 return years+" years and "+days+" days";

                           else

                                 return years+" years";

                    }

             }else

             {

                    if(months > 0)

                    {

                           if(days > 0)

                                 return months+" months and "+days+" days";

                           else

                                 return months+" months ";

                    }else

                    {

                           if(days > 0)

                                 return days+" days";

                           else

                                 return "0 days";

                    }

             }

       }

      

       // method to return the number of days since birth

       public long daysSinceBirth()

       {

             LocalDate currentDate = LocalDate.now();

             LocalDate birthDate = LocalDate.of(birthYear, birthMonth, birthDay);

            

             long noOfDays = (ChronoUnit.DAYS.between(birthDate, currentDate));

            

             return noOfDays;

       }

      

       // toString() method

       public String toString()

       {

             return getLName()+ " "+getFName() + " is "+computeAge();

       }

       // returns if two Athletes are equal or not

       public boolean equals(Athlete other)

       {

             return( (lName.equals(other.lName)) && (fName.equals(other.fName))

                           && (birthDay == other.birthDay) && (birthYear == other.birthYear ) && (birthMonth == other.birthMonth) );

       }

}

//end of Athlete.java

Add a comment
Know the answer?
Add Answer to:
**Only need the bold answered Implement the Athlete, Swimmer, Runner, and AthleteRoster classes below. Each class...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I ONLY need question 2 part C AND D answered...it is in bold. Please do not...

    I ONLY need question 2 part C AND D answered...it is in bold. Please do not use hash sets or tables. In java, please implement the classes below. Each one needs to be created. Each class must be in separate file. The expected output is also in bold. I have also attached the driver for part 4 to help. 1. The Student class should be in the assignment package. a. There should be class variable for first and last names....

  • In Java* Please implement a class called "MyPet". It is designed as shown in the following...

    In Java* Please implement a class called "MyPet". It is designed as shown in the following class diagram. Four private instance variables: name (of the type String), color (of the type String), gender (of the type char) and weight(of the type double). Three overloaded constructors: a default constructor with no argument a constructor which takes a string argument for name, and a constructor with take two strings, a char and a double for name, color, gender and weight respectively. public...

  • In this practical task, you need to implement a class called MyTime, which models a time...

    In this practical task, you need to implement a class called MyTime, which models a time instance. The class must contain three private instance variables: hour, with the domain of values between 0 to 23. minute, with the domain of values between 0 to 59. second, with the domain of values between 0 to 59. For the three variables you are required to perform input validation. The class must provide the following public methods to a user: MyTime() Constructor. Initializes...

  • Create an abstract class “Appointment” that represents an event on a calendar. The “Appointment” class will...

    Create an abstract class “Appointment” that represents an event on a calendar. The “Appointment” class will have four instance variables: • An instance variable called “year” which will be of type int • An instance variable called “month” which will be of type int • An instance variable called “day” which will be of type int • An instance variable called “description” which will be of type String The “Appointment” class must also implement the following methods: • A getter...

  • please write in Java and include the two classes Design a class named Fan (Fan.java) to...

    please write in Java and include the two classes Design a class named Fan (Fan.java) to represent a fan. The class contains: An int field named speed that specifies the speed of the fan. A boolean field named fanStatus that specifies whether the fan is on (default false). A double field named radius that specifies the radius of the fan (default 5). A string field named color that specifies the color of the fan (default blue). A no-arg (default) constructor...

  • Please help me with this code. Thank you Implement the following Java class: Vehicle Class should...

    Please help me with this code. Thank you Implement the following Java class: Vehicle Class should contain next instance variables: Integer numberOfWheels; Double engineCapacity; Boolean isElectric, String manufacturer; Array of integers productionYears; Supply your class with: Default constructor (which sets all variables to their respective default values) Constructor which accepts all the variables All the appropriate getters and setters (you may skip comments for this methods. Also, make sure that for engineCapacity setter method you check first if the vehicle...

  • DIRECTIONS FOR THE WHOLE PROJECT BELOW BigInt class The purpose of the BigInt class is to...

    DIRECTIONS FOR THE WHOLE PROJECT BELOW BigInt class The purpose of the BigInt class is to solve the problem using short methods that work together to solve the operations of add, subtract multiply and divide.   A constructor can call a method called setSignAndRemoveItIfItIsThere(). It receives the string that was sent to the constructor and sets a boolean variable positive to true or false and then returns a string without the sign that can then be processed by the constructor to...

  • Need help to create general class Classes Data Element - Ticket Create an abstract class called...

    Need help to create general class Classes Data Element - Ticket Create an abstract class called Ticket with: two abstract methods called calculateTicketPrice which returns a double and getld0 which returns an int instance variables (one of them is an object of the enumerated type Format) which are common to all the subclasses of Ticket toString method, getters and setters and at least 2 constructors, one of the constructors must be the default (no-arg) constructor. . Data Element - subclasses...

  • Make a LandTract class with the following fields: LandTract is a rectangle. * length - an...

    Make a LandTract class with the following fields: LandTract is a rectangle. * length - an int containing the tract's length * width - an int containing the tract's width The class should have a constructor with two arguments length and width and assign these to the class variables. Now define a Copy Constructor: The constructor that you will write will be a copy constructor that uses the parameter LandTract object to make a duplicate LandTract object, by copying the...

  • Implement the classes in the following class diagram. The Book class implements the Comparable interface. Use impl...

    Implement the classes in the following class diagram. The Book class implements the Comparable interface. Use implements Comparable<Book> in the class definition. Now, all book objects are instances of the java.lang.Comparable interface. Write a test program that creates an array of ten books. 1. Use Arrays.sort( Book[]l books) from the java.util package to sort the array. The order of objects in the array is determined using compareTo...) method. 2. Write a method that returns the most expensive book in the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT