I’m taking a java class and the instructor has had us build a HashMap like this:
Map<String, SortedSet<Car>> makeSetMap = new HashMap<String, SortedSet<Car>>();
The Car objects are read in from a file of cars (like Toyota Corolla 8 90000) and do some processing to get them into the Hashmap as described above. So the map’s key is a string which ends up being a manufacturer name (Toyota) and then the values are SortedSet of Cars.
Later in the app i’m supposed to set it up so a user can select which model he wants to have displayed and then it will display just car data that are from that model. Right now I’m just stuck on figuring how to access all the data in the whole thing. I’ve written some code for the Hashmap and I can get the Manufacturer names to display with an iterator, but I can’t figure out how to display the individual car data. 🙁
Here’s what I have so far – it’s a snippet, but I think you guys can figure it out:
//I'm starting to have trouble here..
Set<String> brands = makeSetMap.keySet();
System.out.println("Brands are: " + brands.toString());
Iterator<String> brandsIt = brands.iterator();
while (brandsIt.hasNext())
{
SortedSet<Car> brandmodels;
//brandmodels = brandsIt.next();
//System.out.println("Working on: " +brandmodels.toString());
}
Help! Thanks to anyone who can straighten me out.
To print all the car models for each manufacturer:
assuming your
Carclass has atoStringoverride.