having a problem with this java homework where I input Olympians into the array list: Name, Gold, silver, bronze medals. If the name of the olympian searched is found then print out the name and the medals he got, else print an error message. This is the code so far to input the name and medals.
public class Analyser {
private ArrayList <Olympian> olympians;
public Analyser() {
olympians = new ArrayList<Olympian>();
}
public void addOlympian (String name, int gold, int silver, int bronze) {
olympians.add(new Olympian(name, gold, silver, bronze));
}
}
Before asking for help with the code itself, you need to figure out a few things:
searchOlympian()
function should take.Olympian
in the ArrayList
, given the name.Olympian
isn't in your list.A few hints:
String.equals(String otherString)
will return true if the strings are equal.for (Olympian olympian : olympians)
will help you go through each Olympian
. Olympian
, then the Olympian
isn't in the list.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.