Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

i need help with commpressedArray.java class public void setMarker(CityMarker) o Sets marker public String toString() o Returns the city name CompressedArray.java This class represents the

i need help with commpressedArray.java class

image text in transcribedimage text in transcribed

public void setMarker(CityMarker) o Sets marker public String toString() o Returns the city name CompressedArray.java This class represents the array that has been compressed from a matrix (2D array) into a linear array that excludes elements from the diagonal and any elements above or to the right of the diagonal. Only elements below or to the left of the matrix diagonal must be included in the CompressedArray. The class must have the following private variables: origArray Size (int) array (double() The class must have the following public methods: public CompressedArray(double[]0) [constructor] o Takes in a 2D double array (double(0) which represents the original array" o Initialize the linear double array (instance variable array) and copy the elements from the original array into this linear array so that it contains only the lower-left triangle elements of the original array (the elements to the left and below the diagonal). The elements from this triangle must be added to the CompressedArray in order from left to right and top to bottom. o Hint: Read the description near the top of this document to determine the required capacity for this CompressedArray. public int getLength() o Returns the length of the new, compressed array public double getElement(int) o Returns the element in the new, compressed array stored at the given index public boolean equals(CompressedArray) o Checks equality between the two CompressedArray objects by checking if they have the same length and that all the elements are identical in the same order public String toString() o Builds a string that contains the CompressedArray and formats it in a trianglular structure to look like the lower left corner of a matrix. Each element should take up exactly 8 characters and show 2 decimal places. o Hint: Use String.format("%8.2f", element) for each element and remember to add a newline at the correct places Program.java This class, as its name suggests, will be the main heart of the program. It will be the entry point of the program, read in a file of cities and create objects for each of them, contain the array of those cities, and create a CompressedArray containing the distances between each of the cities read in from the file. The class must have the following private variables: cityCount (int) cityArray (City) array (CompressedArray) The class must have the following methods: public CompressedArray(String, boolean) [constructor] o Takes in a String representing the file to load (i.e. "cities 1.txt") and a boolean (showMap) that indicates whether or not the map GUI should be displayed o Initialize cityArray with 3 cells o Create an object of MyFileReader or use your own code to read in a text file, and load in the file with the given name. o Read in each line from the file and create a City object containing the city name, and the x and y values from the file (look at the text file to see this format). Add the city object to the cityArray and expand the capacity if needed. o If the boolean (showMap) is true, then create a Map object and call addCity() on the Map object for each city in the cityArray. This will add the marker icons to the map for each city public City() getCityList() o Returns cityArray private void expandCapacity (int) o Expands the capacity of cityArray by adding 3 additional slots to the array public double distBetweenCities(City City) o Calculates the Euclidean distance between the two given Cities public void compare Distances() o Create a 2D double array (i.e. double(0) with a size of N by N, where N is the number of cities in cityArray. Loop through every combination of pairs of cities and call distBetweenCit ) for each pair. Save this result into the double | array in the appropriate cell. public CompressedArray getArray() o Returns array public void setMarker(CityMarker) o Sets marker public String toString() o Returns the city name CompressedArray.java This class represents the array that has been compressed from a matrix (2D array) into a linear array that excludes elements from the diagonal and any elements above or to the right of the diagonal. Only elements below or to the left of the matrix diagonal must be included in the CompressedArray. The class must have the following private variables: origArray Size (int) array (double() The class must have the following public methods: public CompressedArray(double[]0) [constructor] o Takes in a 2D double array (double(0) which represents the original array" o Initialize the linear double array (instance variable array) and copy the elements from the original array into this linear array so that it contains only the lower-left triangle elements of the original array (the elements to the left and below the diagonal). The elements from this triangle must be added to the CompressedArray in order from left to right and top to bottom. o Hint: Read the description near the top of this document to determine the required capacity for this CompressedArray. public int getLength() o Returns the length of the new, compressed array public double getElement(int) o Returns the element in the new, compressed array stored at the given index public boolean equals(CompressedArray) o Checks equality between the two CompressedArray objects by checking if they have the same length and that all the elements are identical in the same order public String toString() o Builds a string that contains the CompressedArray and formats it in a trianglular structure to look like the lower left corner of a matrix. Each element should take up exactly 8 characters and show 2 decimal places. o Hint: Use String.format("%8.2f", element) for each element and remember to add a newline at the correct places Program.java This class, as its name suggests, will be the main heart of the program. It will be the entry point of the program, read in a file of cities and create objects for each of them, contain the array of those cities, and create a CompressedArray containing the distances between each of the cities read in from the file. The class must have the following private variables: cityCount (int) cityArray (City) array (CompressedArray) The class must have the following methods: public CompressedArray(String, boolean) [constructor] o Takes in a String representing the file to load (i.e. "cities 1.txt") and a boolean (showMap) that indicates whether or not the map GUI should be displayed o Initialize cityArray with 3 cells o Create an object of MyFileReader or use your own code to read in a text file, and load in the file with the given name. o Read in each line from the file and create a City object containing the city name, and the x and y values from the file (look at the text file to see this format). Add the city object to the cityArray and expand the capacity if needed. o If the boolean (showMap) is true, then create a Map object and call addCity() on the Map object for each city in the cityArray. This will add the marker icons to the map for each city public City() getCityList() o Returns cityArray private void expandCapacity (int) o Expands the capacity of cityArray by adding 3 additional slots to the array public double distBetweenCities(City City) o Calculates the Euclidean distance between the two given Cities public void compare Distances() o Create a 2D double array (i.e. double(0) with a size of N by N, where N is the number of cities in cityArray. Loop through every combination of pairs of cities and call distBetweenCit ) for each pair. Save this result into the double | array in the appropriate cell. public CompressedArray getArray() o Returns array

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

Mastering Apache Cassandra 3 X An Expert Guide To Improving Database Scalability And Availability Without Compromising Performance

Authors: Aaron Ploetz ,Tejaswi Malepati ,Nishant Neeraj

3rd Edition

1789131499, 978-1789131499

More Books

Students also viewed these Databases questions