getTeamSize: returns the number of runners that are currently on the team.
getmostReliableRunner: takes an int representing the gender and an int representing the race parameters and returns the most reliable runner of that gender in that particular race type based on the standard deviation.
getStandardDeviation: Need to be able to get the Standard Deviation of a set of numbers that are stored in a file. (Dont really know how to call that file either.. )
PLEASE HELP I AM KIND OF LOST ON THESE 3 METHODS!!!!!
THANKYOU!
10 Replies  5663 Views  Last Post: 26 October 2010  03:49 PM
#1
Having problems coming up with these methods! Please HELP!
Posted 25 October 2010  11:08 AM
Replies To: Having problems coming up with these methods! Please HELP!
#2
Re: Having problems coming up with these methods! Please HELP!
Posted 25 October 2010  05:04 PM
Quote
getTeamSize: returns the number of runners that are currently on the team.
This is probably associate with your Team class, which has an instance variable representing the Team size or the number of runners. Your getter method should simply return that variable.
Quote
getmostReliableRunner: takes an int representing the gender and an int representing the race parameters and returns the most reliable runner of that gender in that particular race type based on the standard deviation.
If I had to guess, there is a Tournament/Competition class that you are using which has some sort of Collection associating Teams with the Races they are in. The int params you pass are to be used to help narrow down which Race and Runners to look at. See the documentation for the Collection being used for more information on which methods to invoke.
Quote
getStandardDeviation: Need to be able to get the Standard Deviation of a set of numbers that are stored in a file. (Dont really know how to call that file either.. )
There are plenty of formulas to calculate Standard Deviation on the internet. As for File I/O, check out the DIC Tutorials Section.
Hopefully this will help get you started some. We are happy to help more, provided you show us your good faith efforts at implementing solutions to these problems. Don't forget to specifically describe your problems or errors.
#3
Re: Having problems coming up with these methods! Please HELP!
Posted 26 October 2010  12:08 PM
Ok so far i have got this..... Will you look over this and maybe make corrections where they are needed....
Thank you so much you are awesome!!!!
Edited by macosxnerd101: Please, .
Thank you so much you are awesome!!!!
public double getStandardDeviation(int raceTypeIn) { double average = 0.0; double total = 0.0; double deviation; double sumOfSquares = 0.0; double variance; if (raceTypeIn == METER100) { for (int i = 0; i <time100.length; i++) { total += time100[i]; average = total / time100.length; } } else if (raceTypeIn == METER200) { for (int i = 0; i < time200.length; i++) { variance = sumOfSquares / (time200.length  1); // variance is deviatio squared. deviation = Math.sqrt(variance); // deviation = Standard Deviation. } } else { total = 1.0; } return total; } public Runner getMostReliableRunner(int genderIn, int raceTypeIn) { gender = genderIn; raceType = raceTypeIn; } public void loadFromFile(String fileNameIn) throws IOException { File f = new File(fileNameIn); String name; int gender; Scanner scan = new Scanner(f); String line = scan.nextLine(); String[] splitLine = line.split(", "); double[] times = new double[5]; Runner r; int counter = 0; if (runners[0] != null) { for (int i = 0; i < runners.length; i++) { runners[i] = null; } } if (scan.hasNext()) { name = splitLine[0]; if (splitLine[1] == "f") { gender = Runner.FEMALE; } else { gender = Runner.MALE; } r = new Runner(name, gender); for (int i = 0; i < 5; i++) { times[i] = Double.parseDouble(splitLine[2 + i]); } r.setTimes(Runner.METER100, times); for (int i = 0; i < 5; i++) { times[i] = Double.parseDouble(splitLine[7 + i]); } r.setTimes(Runner.METER200, times); runners[counter] = r; counter++; } }
Edited by macosxnerd101: Please, .
#4
Re: Having problems coming up with these methods! Please HELP!
Posted 26 October 2010  12:57 PM
Does it output the answers as you've written out by hand? Because, you know, when doing math in Java, you should do a couple of sample tests by hand to verify the correct answer.
#5
Re: Having problems coming up with these methods! Please HELP!
Posted 26 October 2010  01:13 PM
Yes i have and it seems to be ok.....
#6
Re: Having problems coming up with these methods! Please HELP!
Posted 26 October 2010  01:22 PM
In this method, you need to return a Runner. You simply modify the instance variables to match the values of the parameters. You need to perform a search on the given Race, find the matching Runner, and return it.
public Runner getMostReliableRunner(int genderIn, int raceTypeIn)
#7
Re: Having problems coming up with these methods! Please HELP!
Posted 26 October 2010  01:30 PM
ok i got this..... can one of you maybe help me re write it into a simpler form....
less complex....
Thanks.
Edited by macosxnerd101: Added code tags. Please use them in the future.
less complex....
Thanks.
public Runner getMostReliableRunner(int genderIn, int raceTypeIn) { Runner mostReliable; double deviation = 100.0; if (runners[0] != null) { mostReliable = runners[0]; for (int i = 0; i < runners.length; i++) { if (runners[i].getGender() == genderIn) { if (runners[i].getStandardDeviation(raceTypeIn) < deviation) { mostReliable = runners[i]; deviation = runners[i].getStandardDeviation(raceTypeIn); } } } return mostReliable; } else { return null; } }
Edited by macosxnerd101: Added code tags. Please use them in the future.
#8
Re: Having problems coming up with these methods! Please HELP!
Posted 26 October 2010  02:37 PM
No need to calculate standard deviation twice. Store the result of the first call into a variable, and use that variable to compare with.
int tempDev = runners[i].getStandardDeviation(raceTypeIn); if(tempDev < deviation){ mostReliable = runners[i]; deviation = tempDev; }
#9
Re: Having problems coming up with these methods! Please HELP!
Posted 26 October 2010  03:00 PM
Dude, you do not know how much i appreciate this help.... all this is due at 10 tonight so i will be doing this until then....
Have any suggestions for this method?
public Runner selectCompetitor(int genderIn,
int raceTypeIn, double targetTime)
{
Runner bestCompetitor;
double time = 0.0;
if (ran[0] != null)
{
bestCompetitor = ran[0];
for (int i = 0; i < ran.length; i++)
{
if (ran[i].getGender() == genderIn)
{
if (ran[i].getAverageTime(raceTypeIn) < targetTime
&& ran[i].getAverageTime(raceTypeIn) > time)
{
bestCompetitor = ran[i];
time = ran[i].getAverageTime(raceTypeIn);
}
}
}
return bestCompetitor;
}
else
{
return null;
}
}
Have any suggestions for this method?
public Runner selectCompetitor(int genderIn,
int raceTypeIn, double targetTime)
{
Runner bestCompetitor;
double time = 0.0;
if (ran[0] != null)
{
bestCompetitor = ran[0];
for (int i = 0; i < ran.length; i++)
{
if (ran[i].getGender() == genderIn)
{
if (ran[i].getAverageTime(raceTypeIn) < targetTime
&& ran[i].getAverageTime(raceTypeIn) > time)
{
bestCompetitor = ran[i];
time = ran[i].getAverageTime(raceTypeIn);
}
}
}
return bestCompetitor;
}
else
{
return null;
}
}
#10
Re: Having problems coming up with these methods! Please HELP!
Posted 26 October 2010  03:21 PM
Yes please use code tags as I have asked multiple times. It makes it much easier for us to read your code. You can use the EDIT button on your post to add them.
Code tags: .
Code tags: .
#11
Re: Having problems coming up with these methods! Please HELP!
Posted 26 October 2010  03:49 PM
This is my last method!!!!!
If there is any way to put this into a much simpler form and a way to maybe shorten it up can you please help!!!
THIS IS IT !!!! THANKS!!!
I also could not find the edit button..... my brain is also fried because I have been doing this for almost 9 hrs now, I am very sorry for that.
didnt mean to post the getMostReliable runner method again just ignore that one!!
If there is any way to put this into a much simpler form and a way to maybe shorten it up can you please help!!!
THIS IS IT !!!! THANKS!!!
I also could not find the edit button..... my brain is also fried because I have been doing this for almost 9 hrs now, I am very sorry for that.
public void loadFromFile(String fileNameIn) throws IOException { File f = new File(fileNameIn); String name; int gender; double[] times = new double[5]; Runner r; int counter = 0; if (f.exists()) { Scanner scan = new Scanner(f); if (runners[0] != null) { for (int i = 0; i < runners.length; i++) { runners[i] = null; } } teamName = scan.nextLine(); while (scan.hasNext()) { runners[counter] = new Runner("", 0); String line = scan.nextLine(); String[] splitLine = line.split(","); name = splitLine[0]; runners[counter].setName(name); if (splitLine[1].equals("f")) { gender = Runner.FEMALE; } else { gender = Runner.MALE; } r = new Runner(name, gender); for (int i = 0; i < 5; i++) { times[i] = Double.parseDouble(splitLine[2 + i]); } r.setTimes(Runner.METER100, times); for (int i = 0; i < 5; i++) { times[i] = Double.parseDouble(splitLine[7 + i]); } r.setTimes(Runner.METER200, times); runners[counter] = r; counter++; } } } /** *Gets the most reliable runner based on deviation. *@param genderIn Gender of runner *@param raceTypeIn Race type *@return mostReliable Most reliable runner */ public Runner getMostReliableRunner(int genderIn, int raceTypeIn) { Runner mostReliable; double deviation = 100.0; if (runners[0] != null) { mostReliable = runners[0]; for (int i = 0; i < runners.length; i++) { if (runners[i].getGender() == genderIn) { if (runners[i].getStandardDeviation(raceTypeIn) < deviation) { mostReliable = runners[i]; deviation = runners[i].getStandardDeviation(raceTypeIn); } } } return mostReliable; } else { return null; } }
didnt mean to post the getMostReliable runner method again just ignore that one!!
Page 1 of 1
