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

In honor of the Winter Olympics, our Projects this semester will have a Winter O

ID: 3707961 • Letter: I

Question

In honor of the Winter Olympics, our Projects this semester will have a Winter Olympics theme. For Project #1, we'll be building, documenting and testing Objects and Enums that we will need to simulate our own Winter Olympics. The specification for our Objects, Enums and Driver is provided below. Also provided below are UML Diagrams depicting what our Objects should contain.

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

Athlete Object (Remember to consult the UML for attribute data types, method parameters and method return data types!):

Athletes should have:

A name attribute

A country attribute

A type of event attribute

A skill attribute

A counter for number of GOLD medals won (we will ignore silver and bronze medals for this version of the project)

A full parameter constructor (a constructor with a parameter for each of the 5 fields)

A default parameter constructor

A get method for each field

A set method for each field

Verify at least 1 character was entered for the name! If not, set the Athlete's name as DEFAULT.

Verify that skill entered is between 0 and 10! If not, set the Athlete's skill as 0.

Verify that gold medals entered is not negative! If value entered for medals is negative, set medals value to 0.

A toString() method

An equals() method

MAKE SURE YOU HAVE JAVADOC COMMENTS FOR THE CLASS AND THE METHODS!!!

Class Level JavaDoc comments need AT LEAST:

The author(s) tag(s)

A description about what this class/object is for

Method Level JavaDoc comments need AT LEAST:

A description of what the method does

param tag(s) describing the input data if the method needs input data

return tag describing the returned output data if the method returns data

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

Event Object (Remember to consult the UML for attribute data types, method parameters and method return data types!):

Events should have:

A specific event name attribute

A venue attribute

A type of event attribute

A list of Athletes attribute

A full parameter constructor (a constructor with a parameter for each of the 4 fields)

A default parameter constructor

A get method for each field

A set method for each field

Verify that list of Athletes attribute has at least 1 Athlete! Otherwise, print an error message saying that competitions need at least 1 Athlete in order to run.

A toString() method

An equals() method

A compete() method which calculates the winning Athlete. This method should work by looping through the list of Athletes and, for each Athlete, generating a random number from 1 to 100 (both values inclusive) and adding the Athlete's skill attribute to the random number. The Athlete with the greatest sum (random value + Athlete's skill) is the winner of the event.

MAKE SURE YOU HAVE JAVADOC COMMENTS FOR THE CLASS AND THE METHODS!!!

Class Level JavaDoc comments need AT LEAST:

The author(s) tag(s)

A description about what this class/object is for

Method Level JavaDoc comments need AT LEAST:

A description of what the method does

param tag(s) describing the input data if the method needs input data

return tag describing the returned output data if the method returns data

Explanation / Answer

import java.util.Collections;
import java.util.List;
import java.util.Random;

/**
* @author
* Event class hold details about events
* members eventName, venue,eventType,listOfAthletes
*
*/
public class Event {

String eventName;
String venue;
String eventType;
List<Athlete> listOfAthlete;
/**
* @param eventName
* @param venue
* @param eventType
* @param listOfAthlete
*/
public Event(String eventName, String venue, String eventType, List<Athlete> listOfAthlete) {
super();
this.eventName = eventName;
this.venue = venue;
this.eventType = eventType;
if(listOfAthlete.size()>1)
this.listOfAthlete = listOfAthlete;
else
System.out.println("At leat one Athlete needed to run the event");
}

public Event(){

}

/**
* @return the eventName
*/
public String getEventName() {
return eventName;
}

/**
* @param eventName the eventName to set
*/
public void setEventName(String eventName) {
this.eventName = eventName;
}

/**
* @return the venue
*/
public String getVenue() {
return venue;
}


/**
* @param venue the venue to set
*/
public void setVenue(String venue) {
this.venue = venue;
}

/**
* @return the eventType
*/
public String getEventType() {
return eventType;
}

/**
* @param eventType the eventType to set
*/
public void setEventType(String eventType) {
this.eventType = eventType;
}

/**
* @return the listOfAthlete
*/
public List<Athlete> getListOfAthlete() {
return listOfAthlete;
}

/**
* @param listOfAthlete the listOfAthlete to set
*/
public void setListOfAthlete(List<Athlete> listOfAthlete) {
if(listOfAthlete.size()>=1)
this.listOfAthlete = listOfAthlete;
else
System.out.println("At leat one Athlete needed to run the event");
}

/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return "Event [eventName=" + eventName + ", venue=" + venue + ", eventType=" + eventType + ", listOfAthlete="
+ listOfAthlete + "]";
}




/* (non-Javadoc)
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Event other = (Event) obj;
if (eventName == null) {
if (other.eventName != null)
return false;
} else if (!eventName.equals(other.eventName))
return false;
if (eventType == null) {
if (other.eventType != null)
return false;
} else if (!eventType.equals(other.eventType))
return false;
if (listOfAthlete == null) {
if (other.listOfAthlete != null)
return false;
} else if (!listOfAthlete.equals(other.listOfAthlete))
return false;
if (venue == null) {
if (other.venue != null)
return false;
} else if (!venue.equals(other.venue))
return false;
return true;
}

/*
* Computes the winner based on skill and random number
* Return Winner Athlete
*/
public Athlete compete(){

Athlete winner = null;

List<Athlete> tempList = this.listOfAthlete;
Random rand = new Random();
for(Athlete a:tempList){
int score = rand.nextInt(101);
if(score==0)
score +=1;
score+=a.getSkill();
a.setSkill(score);
}
//Sort the list based on score
Collections.sort(tempList);
// Set first one as winner since sorted decender order
winner = tempList.get(0);
return winner;
}


}

//=======================================
/**
* @author
*
*/
public class Athlete implements Comparable<Athlete>{
    String name;
String country;
String eventType;
int skill;
int noOfGold;



/**
* @param name
* @param country
* @param eventType
* @param skill
* @param noOfGold
*/
public Athlete(String name, String country, String eventType, int skill, int noOfGold) {
super();
if(name.length()>=1)
this.name = name;
else
this.name = "DEFAULT";
this.country = country;
this.eventType = eventType;
if(skill>=0 && skill<=10)
this.skill = skill;
else
this.skill = 0;
if(noOfGold>=0)
this.noOfGold = noOfGold;
else
this.noOfGold = 0;
}

public Athlete(){

}

/**
* @return the name
*/
public String getName() {
return name;
}


/**
* @param name the name to set
*/
public void setName(String name) {
if(name.length()>=1)
this.name = name;
else
this.name = "DEFAULT";
}

/**
* @return the country
*/
public String getCountry() {
return country;
}

/**
* @param country the country to set
*/
public void setCountry(String country) {
this.country = country;
}

/**
* @return the eventType
*/
public String getEventType() {
return eventType;
}

/**
* @param eventType the eventType to set
*/
public void setEventType(String eventType) {
this.eventType = eventType;
}

/**
* @return the skill
*/
public int getSkill() {
return skill;
}

/**
* @param skill the skill to set
*/
public void setSkill(int skill) {
if(skill>=0 && skill<=10)
this.skill = skill;
else
this.skill = 0;
}


/**
* @return the noOfGold
*/
public int getNoOfGold() {
return noOfGold;
}

/**
* @param noOfGold the noOfGold to set
*/
public void setNoOfGold(int noOfGold) {
if(noOfGold>=0)
this.noOfGold = noOfGold;
else
this.noOfGold = 0;
}

/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return "Athlete [name=" + name + ", country=" + country + ", eventType=" + eventType + ", skill=" + skill
+ ", noOfGold=" + noOfGold + "]";
}



/* (non-Javadoc)
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Athlete other = (Athlete) obj;
if (country == null) {
if (other.country != null)
return false;
} else if (!country.equals(other.country))
return false;
if (eventType == null) {
if (other.eventType != null)
return false;
} else if (!eventType.equals(other.eventType))
return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
if (noOfGold != other.noOfGold)
return false;
if (skill != other.skill)
return false;
return true;
}

@Override
public int compareTo(Athlete o) {
// TODO Auto-generated method stub
if(this.skill > o.skill)
return 1;
else if (this.skill < o.skill)
return -1;
return 0;
}

}

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