Question: Write a program that allows the user to edit an atlas of cities and states. The user should be able to insert and delete states

Write a program that allows the user to edit an atlas of cities and states. The user should be able to insert and delete states as well as insert and delete cities belonging to specific states. (Hint start with the following code)

(Java Programming)

import java.util.*;

public class GenericsDemo {

/** * @param args */ public static void main(String[] args) { // We have no idea how many states ahead of time, so we'll use a // dynamic data structure ArrayList aFewStates = new ArrayList(); aFewStates.add("New York"); aFewStates.add("Ohio"); aFewStates.add("Nevada"); aFewStates.add("Washington"); aFewStates.add("New York"); for(String state : aFewStates) { System.out.println(state); } System.out.println(); System.out.println(); // We'll use inheritance and make this REALLY weird and powerful! // Everything in Java is an Object... right? ArrayList things = new ArrayList(); things.add(7); things.add("Hello There"); things.add(new Scanner(System.in)); things.add(new Random()); things.add(things); for (Object thing : things) { System.out.println(thing); } System.out.println(); System.out.println(); // We'll use a tree to sort things and remove duplicates TreeSet stateSet = new TreeSet(aFewStates); for(String state : stateSet) { System.out.println(state); } System.out.println(); System.out.println(); // Let's keep track of some cities! TreeMap> atlas = new TreeMap>(); atlas.put("Ohio", new TreeSet()); atlas.put("New York", new TreeSet()); atlas.put("Pennsylvania", new TreeSet()); atlas.put("Florida", new TreeSet()); atlas.get("New York").add("Utica"); atlas.get("New York").add("Buffalo"); atlas.get("Ohio").add("Columbus"); atlas.get("Ohio").add("Cleveland"); atlas.get("Pennsylvania").add("Pittsburgh"); atlas.get("Pennsylvania").add("Scranton"); atlas.get("Florida").add("Tampa"); atlas.get("Florida").add("Miami"); for (String state : atlas.keySet()) { System.out.println(state + ":"); for (String city : atlas.get(state)) { System.out.println(" " + city); } } } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!