PS #4
Posted: Sat Oct 16, 2010 10:33 am
Hi, I've been getting some questions about the homework. The idea is that you are using a String as the key to retrieve a List of GeometricShapes.
So, for instance:
When the user selects "Circles" from the GUI (using whatever kind of interface element you want-- a button or a textbox or a drop-down list) that will get the List of circles from the shapeMap:
and then loop through that list and render each circle.
-Angus
So, for instance:
Code: Select all
Map<String, List<GeometricShape>> shapeMap = new HashMap<String, List<GeometricShape>>();
List<GeometricShape> circleList = new List<GeometricShape>();
Circle c1 = new Circle(); //pretend this constructor makes a random cricle, you can do something different in your code if you want.
Circle c2 = new Circle();
cricleList.add(c1); //this works because your Circle will extend GeometricShape
circleList.add(c2);
shapeMap.put("Circles", circleList);
Code: Select all
List<GeometricShape> currentList = shapeMap.get("Circles");
and then loop through that list and render each circle.
-Angus