You could try and do as follows:
Read the data from the text file and split it using the .split(String regex)
method:
try{
Scanner scan = new Scanner(new File("C:\\Users\\Dustin\\Desktop\\test.txt"));
TreeSet<String> ts = new TreeSet<String>();
while(scan.hasNextLine()){
String[] strArray = scan.nextLine().split("\\s+"); //the will yield an array having {"001", "City", "5000.00", "101"}
Since you want to group by ID, you could take a look at the HashMap
and add this line: Map<String, Double> map = new HashMap<String, Double>();
TreeSet<String> ts = new TreeSet<String>();
Map<String, Double> map = new HashMap<String, Double>()
When you read the data, from the file, you will check to see if you have already read a value with the same ID:
if(map.containsKey(strArray[3]))
{
map.put(strArray[3], map.get(strArray[3]) + Double.parseDouble(strArray[2].trim()));
}
else
{
map.put(strArray[3], Double.parseDouble(strArray[2].trim());
}
And add the data to your set:
ts.add(strArray[1]);
Once that you are ready, you will need to iterate over the set and then, print its content. Once that you will have that done, you will need to iterate over the map and print the key-value pairs.
That being said, since neither data structure caters for ordering, I would recommend that you include the ID's of the values you put in your tree set for clarity:
ts.add(strArray[1] + "(" + strArray[4] + ")");