0% found this document useful (0 votes)
18 views2 pages

Flatworld Parallel Arrays

The document outlines a program called Flatworld that models a world with cities on a Cartesian coordinate plane, detailing their coordinates, exported metals, and prices. It specifies the creation of private arrays for city data and static methods for various functionalities such as retrieving exports, finding cities by export, changing prices, and calculating distances between cities. Additionally, it includes user interaction for calculating distances and managing exports, with an extra credit task for calculating distances and costs for multiple cities.

Uploaded by

downdrift1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views2 pages

Flatworld Parallel Arrays

The document outlines a program called Flatworld that models a world with cities on a Cartesian coordinate plane, detailing their coordinates, exported metals, and prices. It specifies the creation of private arrays for city data and static methods for various functionalities such as retrieving exports, finding cities by export, changing prices, and calculating distances between cities. Additionally, it includes user interaction for calculating distances and managing exports, with an extra credit task for calculating distances and costs for multiple cities.

Uploaded by

downdrift1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

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.

You might also like