More specifically, you are to provide a class called MapBox in a source code fil
ID: 3745874 • Letter: M
Question
More specifically, you are to provide a class called MapBox in a source code file named "MapBox . Java”. Your class must have the following features. . » a default constructor that allocates any needed storage · a public member variable called “locations" that holds a list of objects of the type Location » four public accessor member functions that return (as type double) the coordinates of the bounding box: - Westmost-returns the minimum x-axis coordinate -Eastmost-returns the maximum x-axis coordinate - Southmost _ returns the minimum y-axis coordinate Northmostreturns the maximum y-axis coordinate » a public member function called recordLocation that takes a single Location object as an argument and adds that object to the locations list, but only if the given Location object does not have the same name as any previously recorded location In general, your classes should allow the main method in the provided Ezero class to output correct solutions, including the coordinates of the bounding box and a complete list of locations, without duplicates. Note that this means that the member functions of the class that you implement should write no output to the standard output stream, as this will clutter the output produced by the Ezero class main method. If you include any statements that write output in your code (perhaps as tools for debugging) these should be removed prior to submitting your source code file for evaluation. You will not receive credit for the exercise if your solution produces extraneous output.Explanation / Answer
In order for me to provide you a more correct solution, you would need to provide me the implementation of Location class. For time being, I have written the implementation of Location class too.
Please find the code below.
CODE
=======================
import java.util.ArrayList;
class Location {
private String name;
private double x, y;
public Location (String name, double x, double y) {
this.name = name;
this.x = x;
this.y = y;
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the x
*/
public double getX() {
return x;
}
/**
* @param x the x to set
*/
public void setX(double x) {
this.x = x;
}
/**
* @return the y
*/
public double getY() {
return y;
}
/**
* @param y the y to set
*/
public void setY(double y) {
this.y = y;
}
@Override
public String toString() {
return "Location [name=" + name + ", x=" + x + ", y=" + y + "]";
}
}
public class MapBox {
private ArrayList<Location> locations;
public MapBox() {
locations = new ArrayList<>();
}
public double Westmost() {
if (locations.size() == 0)
throw new ArrayIndexOutOfBoundsException("No elements found");
double min = locations.get(0).getX();
for(int i=1; i<locations.size(); i++) {
if (locations.get(i).getX() < min) {
min = locations.get(i).getX();
}
}
return min;
}
public double Eestmost() {
if (locations.size() == 0)
throw new ArrayIndexOutOfBoundsException("No elements found");
double max = locations.get(0).getX();
for(int i=1; i<locations.size(); i++) {
if (locations.get(i).getX() > max) {
max = locations.get(i).getX();
}
}
return max;
}
public double Sestmost() {
if (locations.size() == 0)
throw new ArrayIndexOutOfBoundsException("No elements found");
double min = locations.get(0).getY();
for(int i=1; i<locations.size(); i++) {
if (locations.get(i).getY() < min) {
min = locations.get(i).getY();
}
}
return min;
}
public double Nestmost() {
if (locations.size() == 0)
throw new ArrayIndexOutOfBoundsException("No elements found");
double max = locations.get(0).getY();
for(int i=1; i<locations.size(); i++) {
if (locations.get(i).getY() > max) {
max = locations.get(i).getY();
}
}
return max;
}
public void recordLocation (Location location) {
for (int i=0; i<locations.size(); i++) {
if (locations.get(i).getName().equalsIgnoreCase(location.getName())) {
return;
}
}
locations.add(location);
}
@Override
public String toString() {
return "MapBox [locations=" + locations + ", Westmost()=" + Westmost() + ", Eestmost()=" + Eestmost()
+ ", Sestmost()=" + Sestmost() + ", Nestmost()=" + Nestmost() + "]";
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.