Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Java programming needs help, code provided below, just need some modification in

ID: 3746841 • Letter: J

Question

Java programming needs help, code provided below, just need some modification in order to get the correct output with the file.

Code for Location.java:

code for Ezero.java:

code for Mapbox.java:

test files:

location-duplicates.dat:

test file : locations-simple.dat

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 - Northmostretums 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. The Java™ utility classes that you are required to use are provided in a ZIP archive file called "EXO.zip which is available in the "Assignments" section of the class CatCourses site, under "Exercise #0". These utilities incl ude: LocationThis object encodes a location on the map. It includes a location name, a longitude (x-axis coordinate), and a latitude (y-axis coordinate. Ezero This object provides a top-level driver that tests your solution. Your code must allow Ezero to produce correct output. The contents of these JavaM utility files will be discussed during a course laboratory session, and inline comments in these files should assist in your understanding of the provided code. Questions are welcome, however, and should be directed to the teaching team.

Explanation / Answer

ANSWER:

CODE;

MapBox.java
import java.util.ArrayList;

/**
* Provides the coordinates of bounding box
* Maintains list of locations without duplicates
*/
class MapBox {

ArrayList<Location> locations; //list of object of type Location

/**
* Default constructor
*/
public MapBox() {
locations=new ArrayList<Location>();
}
  
  

/**
* Add locations to location list after checking for duplication
* @param loc location to be added to list
* @return true if location is added, false other wise
*/
  
boolean recordLocation(Location loc) {
for(int i=0;i<locations.size();i++)
{
if(locations.get(i).equals(loc))
return false;
}
locations.add(loc);
return true;
}

/**
* Return the coordinates of bounding box
* @return the minimum xaxis coordinate
*/
double Westmost() {
double minx=locations.get(0).longitude;
  
for (Location theLoc : locations)
{
if(theLoc.longitude<minx)
minx=theLoc.longitude;
}
return minx;
}
  
/**
* Return the coordinates of bounding box
* @return the maximum xaxis coordinate
*/
double Eastmost() {
double maxx=locations.get(0).longitude;
  
for (Location theLoc : locations)
{
if(theLoc.longitude>maxx)
maxx=theLoc.longitude;
}
return maxx;
}

/**
* Return the coordinates of bounding box
* @return the maximum yaxis coordinate
*/
double Northmost() {
double maxy=locations.get(0).longitude;
  
for (Location theLoc : locations)
{
if(theLoc.latitude<maxy)
maxy=theLoc.latitude;
}
return maxy;
}

/**
* Return the coordinates of bounding box
* @return the minimum yaxis coordinate
*/
double Southmost() {
double miny=locations.get(0).longitude;
  
for (Location theLoc : locations)
{
if(theLoc.latitude<miny)
miny=theLoc.latitude;
}
return miny;
}
  
}

sample input file : locations.dat

abc 23.44 23.55
def 45.8 23.9
ghi 34.6 78.9
abc 23.44 23.55
jkl 34.56 90.8
mno 34.67 23.56
pqr 23.4 12.8
xyz 23.5 67.8

sample output using the above input

BOUNDING BOX TEST
Duplicate Location: abc
The Bounding Box:
West Edge = 23.400000
East Edge = 45.800000
North Edge = 12.800000
South Edge = 12.800000
The Locations:
abc 23.440000 23.550000
def 45.800000 23.900000
ghi 34.600000 78.900000
jkl 34.560000 90.800000
mno 34.670000 23.560000
pqr 23.400000 12.800000
xyz 23.500000 67.800000
BOUNDING BOX TEST COMPLETE

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote