I am trying to make a new method that tells the user what the country with the highest point out of my array is. What I have currently done is inputted 2 country names followed by their highest point name and the number of the highest point, but now I am trying to output the one country that has the indefinite highest point, in my case from what i've added, its Argentina with Aconcagua as its highest point as 6960.
Code: Main file:
public class continentTest
{
public static void main(String[] args) {
Continent southAmerica = new Continent();
Country southAmericanRepublic = new Country("Argentina", new HighestPoint("Aconcagua", 6960));
southAmerica.addCountry(southAmericanRepublic);
Country anotherSouthAmericanRepublic = new Country("Columbia", new HighestPoint("Pico Cristóbal Colón",5730));
southAmerica.addCountry(anotherSouthAmericanRepublic);
System.out.println (southAmerica.toString());
}
}
Other files:
class Country {
String name;
HighestPoint hp;
public Country (String nm, HighestPoint pt) {
name = nm;
hp = pt;
}
public String toString () {
return name + ": " + hp.toString() + "\n";
}
}
class HighestPoint {
String name;
int height;
public HighestPoint (String nm, int ht) {
name = nm;
height = ht;
}
public String toString () {
return name + " " + String.valueOf (height);
}
}
import java.util.*;
class Continent {
ArrayList<Country> countries;
public Continent () {
countries = new ArrayList<Country>();
}
public void addCountry (Country c) {
countries.add (c);
}
public String toString () {
String s = "";
for (Country c : countries)
s += c.toString();
return s;
}
}
I am not quite sure how to take the largest value from an array and display it along with the country name. Any help would be appreciated, thanks!