So I'm trying to build this program for class and the teacher didn't really show us how to do it and is leaving it up to us to figure it out. The directions are as follows:

The program will input the divers name, the scores of the 5 judges, and the degree of difficulty as well select the city the diver is from. Each diver receives a score (0-10) from 5 judges. Dives have different degrees of difficulty ranging from 1.00 to 1.67. When the process diver button is clicked, the program will validate the data. Ensure that a name has been entered and a city has been selected. If not, display and error message box and set the focus back to that field using the requestFocus method. If everything is valid, calculate the diver's score. The diver's score is calculated as follows: all five scores are added. The highest and lowest scores are always assumed to be skewed, or innaccurate, so they are dropped. Divide the resulting score by 3 and multiply that by the degree of difficulty. Add 1 to the number of divers. Count how many dovers are from Dallas, Fort Worth, or other. Determine the top diver -- the one with the highest score. Clear the text fields, unselect the city, and set the focus to the name field using the requestFocus method.

I can do everything except the last part. thats highlighted in red. I don't know how to store the data when the previous data was cleared. Do I have to store the information in a cache or what? I'm not asking for the whole thing to be coded, I just need help knowing what I am supposed to do to get the last part to work.

Member Avatar for coil

If you store the data in an int array or something, then you can simply set the text field to the values in the int array. Later on, when you clear the text field, the data still remains in the array.

I you managed to use an object to store your data for each diver, You might use an ArrayList to store them, and then iterate over the list when you will do the computations you marked in red :

 public int countByCity(String city, List<Data> list){
    int i = 0;
    for(Data data : list){
       if(data.getCity().equals(city)){
          i++;
       }
    }
    return i;
 }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.