Question

In: Computer Science

**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] =======================================

Solutions

Expert Solution

Screenshot

Swimmer.java

import java.time.LocalDate;
import java.time.Period;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;

//Create a parent class Athlete
class Athlete{
   //Attributes
   private String lName;
   private String fName;
   private int birthYear;
   int birthMonth;
   int birthDay;
   char gender;
   //Constructor
   public Athlete(String lName, String fName, int birthYear, int birthMonth, int birthDay, char gender) {
       this.birthYear=birthYear;
       this.birthMonth=birthMonth;
       this.birthDay=birthDay;
       setlName(lName);
       setfName(fName);
       setGender(gender);
   }
   //Setters
   public void setlName(String lName) {
       this.lName = lName;
   }
   public void setfName(String fName) {
       this.fName = fName;
   }
   public void setGender(char gender) {
       this.gender=gender;
   }
   //Getters
   public String getlName() {
       return lName;
   }
   public String getfName() {
       return fName;
   }
   public String getGender() {
       if(Character.toUpperCase(gender)=='M') {
           return "male";
       }
       else if(Character.toUpperCase(gender)=='F') {
           return "female";
       }
       else {
           return "undeclared";
       }
   }
   //Compute age
   public String computeAge() {
       LocalDate ld = LocalDate.of(birthYear,birthMonth,birthDay);
       Period diff = Period.between(ld,LocalDate.now());
       String str="";
       if(diff.getYears()>0) {
           str+=diff.getYears()+" years, ";
       }
       if(diff.getMonths()>0) {
           str+=diff.getMonths()+" months and ";
       }
       if(diff.getDays()>0) {
           str+=" days";
       }
       return str;
   }
   public long daysSinceBirth() {
       LocalDate ld = LocalDate.of(birthYear,birthMonth,birthDay);
       long days=ChronoUnit.DAYS.between(ld,LocalDate.now());
       return days;
   }
   @Override
   public boolean equals(Object obj) {
       if ( obj instanceof Athlete )
           {
              Athlete ath = (Athlete) obj ;
              return ath.fName.equals(this.fName) && ath.lName.equals(this.lName) && ath.daysSinceBirth()==this.daysSinceBirth();
           }
           else
           {
              return false ;
           }
   }
   @Override
   public String toString() {
       return fName+" "+lName+" "+computeAge();
   }
}
//Subclass
public class Swimmer extends Athlete{
   //Attributes
   private String team;
   private ArrayList<String>event;
//Constructor
   public Swimmer(String lName, String fName, int birthYear, int birthMonth, int birthDay, char gender,String team) {
       super(lName, fName, birthYear, birthMonth, birthDay, gender);
       this.team=team;
       event=new ArrayList<String>();
   }
   //Add a single event
   public boolean addEvent(String singleEvent) {
       if(event.size()==0) {
           event.add(singleEvent);  
           return true;
       }
       else {
           if(event.contains(singleEvent)) {
               return false;
           }
           event.add(singleEvent);  
           return true;
       }
   }
   //Add multiple events
   public boolean addEvent(ArrayList<String> multiEvents) {
       if(event.containsAll(multiEvents )|| multiEvents.size()==0) {
           return false;
       }
       else {
           for(int i=0;i<multiEvents.size();i++) {
               if(!event.contains(multiEvents.get(i))) {
                   event.add(multiEvents.get(i));  
               }
           }
           return true;
       }
   }
   //Getter and setters
   public String getTeam() {
       return team;
   }
   public void setTeam(String team) {
       this.team = team;
   }
   public ArrayList<String> getEvent() {
       return event;
   }
   public void setEvent(ArrayList<String> event) {
       this.event = event;
   }
   @Override
   public String toString() {
       String str=super.toString()+"and is a swimmer for team: "+team+" in the following events: [";
       int i=0;
       for(i=0;i<event.size()-1;i++) {
           str+=event.get(i)+",";
       }
       return str+event.get(i)+"]";
   }
}


SwimmerTest.java

import java.util.ArrayList;

public class SwimmerTester {

   public static void main(String[] args) {
       //Create object
       Swimmer s=new Swimmer("Franklin","Missi",1985,5,16,'M',"Colorado Stars");
       //Add an event
       s.addEvent("100m freestyle");
       //Add multi events
       ArrayList<String>events=new ArrayList<String>();
       events.add("100m backstroke");
       events.add("50m backstroke");
       s.addEvent(events);
       //Duplicate entry
       s.addEvent("50m backstroke");
       //Display
        System.out.println(s);
   }
}

---------------------------------------------------------------------------

Output

Missi Franklin 34 years, 4 months and and is a swimmer for team: Colorado Stars in the following events: [100m freestyle,100m backstroke,50m backstroke]


Related Solutions

I ONLY NEED THE LAST PART ANSWERED NPV Your division is considering two investment projects, each...
I ONLY NEED THE LAST PART ANSWERED NPV Your division is considering two investment projects, each of which requires an up-front expenditure of $23 million. You estimate that the investments will produce the following net cash flows: Year Project A Project B 1 $  5,000,000 $20,000,000 2 10,000,000 10,000,000 3 20,000,000 8,000,000 What are the two projects' net present values, assuming the cost of capital is 5%? Round your answers to the nearest dollar. Project A $ Project B $ What...
Design You will need to have at least four classes: a parent class, a child class,...
Design You will need to have at least four classes: a parent class, a child class, a component class, and an unrelated class. The component object can be included as a field in any of the other three classes. Think about what each of the classes will represent. What added or modified methods will the child class have? What added fields will the child class have? Where does the component belong? How will the unrelated class interact with the others?...
Question : Design and implement two classes called InfixToPostfix and PostFixCalculator. The InfixToPrefix class converts an...
Question : Design and implement two classes called InfixToPostfix and PostFixCalculator. The InfixToPrefix class converts an infix expression to a postfix expression. The PostFixCalculator class evaluates a postfix expression. This means that the expressions will have already been converted into correct postfix form. Write a main method that prompts the user to enter an expression in the infix form, converts it into postfix, displays the postfix expression as well as it's evaluation. For simplicity, use only these operators, + ,...
These only need to be short essay answers, I have answered a few already. This is...
These only need to be short essay answers, I have answered a few already. This is due oct. 31st at 11:59 pm ESSAY: RECEIVABLES: Define Accounts Receivable. Accounts Receivable is an account where businesses can keep track of services they have pervaded without the payment from a client. For example, hospitals would use this when journaling the action when a patient is treated without payment. Account Receivables are journaled as increasing with a debit. All of #2 essay questions follow...
Only need what is in bold. Thank you. The Gessing Tire Company manufactures racing tires for...
Only need what is in bold. Thank you. The Gessing Tire Company manufactures racing tires for bicycles. Gessing sells tires for $85 each. Gessing is planning for the next year by developing a master budget by quarters. Gessing’s balance sheet for December 31, 2018, follows: Gessing Tire Company Balance sheet December 31, 2018 Current Assets: Cash                 $    52,000 Accounts Receivable         35,000 Raw Materials Inventory      1,900 Finished Goods Inventory     2,400                          ________ Total Current Assets                 $    91,300 Property, Plant, and Equipment: Equipment...
For my Federal Taxes class the question below has to be answered and has to be...
For my Federal Taxes class the question below has to be answered and has to be approx couple of paragraphs.. any help would be greatly appreciated! Look up the definition of Reforestation amortization. Write a couple of paragraphs about Reforestation amortization and what you learned? Why it's interesting to you and explain?
Please create a python module named homework.py and implement the classes and methods outlined below. Below...
Please create a python module named homework.py and implement the classes and methods outlined below. Below you will find an explanation for each class and method you need to implement. When you are done please upload the file homework.py to Grader Than. Please get started as soon as possible on this assignment. This assignment has many problems, it may take you longer than normal to complete this assignment. This assignment is supposed to represent a group of students in a...
(Code in Java please) You need to implement the GarageDoor, GarageDoorUpCommand and GarageDoorDownCommand classes (similar to...
(Code in Java please) You need to implement the GarageDoor, GarageDoorUpCommand and GarageDoorDownCommand classes (similar to Light, LightOnCommand and LightOffCommand), AND (edited) Implement the CeilingFan class (with state, see p. 220), AND CeilingFanHighCommand (p. 221), CeilingFanMediumCommand, CeilingFanLowCommand, CeilingFanOffCommand (WITH Undo), AND TEST your CeilingFan classes (see pp. 222 and 223), AND Finally, implement and Test the MacroCommand class on pp. 224-227 EXAMPLE output for homework assignment…………… ======= The COMMAND PATTERN ============= guest house garage door is UP guest house garage...
QUESTION 13 Implement in Python and test the classes shown in the UML below. The LibraryItem...
QUESTION 13 Implement in Python and test the classes shown in the UML below. The LibraryItem class shown in the UML, represents an item that the library issues to students. The partial Python code is provided and It has the following attributes. Test the program by creating a list of books and a list of DVDs and printing the details of each element in the list. Attribute Description ID The ID of the item. createdate The date the item was...
In C++, implement a class called setOper that provides several simple set operations. The class only...
In C++, implement a class called setOper that provides several simple set operations. The class only needs to deal with sets that are closed intervals specified by two real numbers; for example, the pair (2.5, 4.5) represent the interval [2.5, 4.5]. The following operations should be supported: - Check if the value x belongs to the given interval. - Check if the value x belongs to the intersection of two intervals. - Check if the value x belongs to the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT