Hello all, after much dissapointment from a previous programming forum I hope I can get an answer from this one :) I'll try to be a specific as possible.
So I have some students which in this case will will be the Key and their mark which will be their Value.
This is my code so far.
The problem I'm having is this runs through the list and ignores duplicates, which it's meant to do but it still needs to count the mark just discard the name.Code:import java.util.*;
import java.io.IOException;
public class StudentMarks {
public static void main(String[] args) throws IOException {
Map<String, Integer> mp = new HashMap<String, Integer>();
mp.put("Simon", 4);
mp.put("Anna", 10);
mp.put("Simon", 4);
mp.put("Anna", 9);
mp.put("Anna", 5);
mp.put("Edward", 10);
Iterator<String> i= mp.keySet().iterator();
String k;
while(i.hasNext()){
k=i.next();
System.out.println(k+"\t"+mp.get(k));
}
}
}
The output needs to be as follows
Merit order
Edward 1 10.0
Anna 3 8.0
Simon 2 4.0
So as you can see Edward as 1 mark with average of 10
Anna has 3 marks with average of 8
Simon has 2 marks with average of 4.
I just can't think what I need to change in that loop to make this happen. Any ideas? Would be much appreciated.
Please try not to type just one line if you could edit my actual code and type in bold what you have changed that would help me understand the code a lot more. Thanks again

