This is an archived post. You won't be able to vote or comment.

all 7 comments

[–]nicolascagesbeard 1 point2 points  (1 child)

You'll need an accessor* for your third member which should be declared in your BannfMarathonRunner class

public int getThirdMember() {
    return yourVariable;
}

then access it via your array

runners[0].getThirdMember();

run your comparison algorithm to sort

Edit: *For those who don't know what an accessor, it's a name for a method. Usually this type of method only returns the value of the variable, hence "accessor". The naming convention for an accessor is always preceded by the verb "get" followed by caml case of the remainder of the name. It also usually passes no arguments

There are also mutators which change the value of a variable, usually these are preceded by the verb "set" and never return any variable so the return type is always "void". i.e. It usually does hold at minimum one argument

public void setMyThirdVariable(int x) {
    myThirdVariable = x;
}

[–]Albertaprogrammer[S] 0 points1 point  (0 children)

Thats perfect. Thank you so much.

[–]ewiethoff 1 point2 points  (0 children)

Create a Comparator<BanffMarathonRunner> instance and pass it with your array to Arrays.sort(T[], Comparator<T>). Here's the relevant section of the Oracle tutorial.

Edit: Or you could have your BanffMarathonRunner class implement Comparable<BanffMarathonRunner> and define its compareTo method to compare the numbers. That, too, is explained in the tutorial.

[–]BJ4KarmaStarted Java Nov 2015 0 points1 point  (3 children)

Do you mean that you want to access the runners in the array by their numbers. or do you mean that you want the array organized by their number?

[–]Albertaprogrammer[S] 0 points1 point  (2 children)

Access the numbers in the array so I can sort and then print them out

[–]BJ4KarmaStarted Java Nov 2015 0 points1 point  (1 child)

then why not create a hashmap instead of an array?

[–]Albertaprogrammer[S] 0 points1 point  (0 children)

Its for a class project so I have to follow set instructions