Flatworld – Parallel Arrays
Flatworld is a world build on a Cartesian coordinate plane. All of the cities are reachable by straight lines. Create the
following arrays as private fields and use initializer lists to populate them in a program called Flatworld.
City X Coordinate Y Coordinate Metal Exported Price
Zion -234 7 Gold 300
Haddonfield 65 48 Silver 210
Smallville 14 -35 Bronze 65
Metropolis -47 76 Gold 290
Mos Eisley 37 98 Silver 190
District X 136 -12 Gold 275
Hill Valley -85 -147 Bronze 70
Create the following static methods all within the same program:
getExport() – Give the method a city, and return its export.
findCityExport() – Give the method an export, and it will display a list of all of the cities who have that export.
changePrice() – Inputs a metal and a price. All cities with that metal will increase (or decrease if negative) by that price
getX() – given a city get its x coordinate.
getY() – given a city get its y coordinate.
calculateDistance() – Given any two cities, return the distance between them. Use the getX() and getY() functions to
return the x and y coordinates for both cities. Then, use the distance formula to get the distance.
listAll() – Create a string that shows all of the information stored. Example:
Zion: Located at -234,7. Export: Gold Price:300
Next city…
In the Main Method:
Ask the users for two cities. Calculate the distance between those cities.
Ask the user for an export. Display all of the cities who have that export.
Ask the user for an export and a price. Increase all of the cities who have that export by that price.
EXTRA CREDIT – ask the user for any number of cities and get the distance to travel to all of them, as well as the cost of
buying the export at each of the locations.