Using the
ASCII file (see last page) with Cities and their Temperatures (in Celsius),
write a
Java application to read the file sequentially into an array of
objects. Include the following functionality: 1. Print the array. [provide
output] 2. Return a reference to the object containing the highest
temperature [provide output] To do this you will require an array of some
object type defined by you. The array size should be set to 30. Each
element of the array will �store� (or reference) an object. As your
program reads each line (a
string), it should split it into two distinct
fields in order to then form an object and store it in the array. The two
fields include a String for �City Name� and an integer for the
�Temperature�. You can use a String �Tokenizer� to split the string
Valletta 29 Alexandria 28 Cairo 20 Johannesburg 27 Lagos 31 Nairobi
27 Casablanca 24 Montreal 23 Washington 27 Boston 19 Moscow 9 Atlanta 24
Havana 30 Kingston 33 Santiago 26 London 21 Calcutta 34 Karachi 30 Madras
33 Shanghai 22 Tokyo 24 Tehran 20 Bombay 31 Rome 25 Paris 24 Madrid 20
Lisbon 23 Frankfurt 23 Amsterdam 22 Dublin 19
What I have attempted so far is;
public class WorldTemperatures { // keyboard input static BufferedReader keyboard = new BufferedReader( new InputStreamReader(System.in)); public static void main(String args[] )throws IOException { String name; int Temperatures, number; System.out.print("How many cities? "); number = Integer.parseInt(keyboard.readLine()); temperatures s[] = new temperatures[number]; // input into the array for(int index = 0; index < number; index++) { System.out.println(); System.out.print("Enter Name of the city" + (index+1) + "? "); name = keyboard.readLine(); System.out.print("Enter Name for " + name + "? "); age = Integer.parseInt(keyboard.readLine()); s[index] = new Cities(name,temperatures); } printArray(s); }// end of main // Prints elements of array - "cities objects" private static void printArray ( cities s[]) // int[] a { System.out.println("Cities List:"); for(int index = 0; index < s.length; index++) { System.out.println(s[index].getCities() + " " + s[index].getTemperatures()); } }// end of method printArray }// end of class ArrayStudent //{ // public static void main (String args[]) //{ //final int Array_Length = 30; //int array [] = new int [Array_LENGTH]; //System.out.printf("cities", "value"); //}