Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Linked Data A Geographic Perspective

Authors: Glen Hart, Catherine Dolbear

1st Edition

1000218910, 9781000218916

Students also viewed these Databases questions

Question

What attracts you about this role?

Answered: 1 week ago

Question

How many states in India?

Answered: 1 week ago

Question

HOW IS MARKETING CHANGING WITH ARTIFITIAL INTELIGENCE

Answered: 1 week ago

Question

Different types of Grading?

Answered: 1 week ago