Need to create a class with these specific tasks, using these given classes/file
ID: 3746762 • Letter: N
Question
Need to create a class with these specific tasks, using these given classes/files. Thank you.
These Below Are given and need to be used in our new class.
You are to provide a JavaTM class that implements a collection of named locations, here called a "map box". In addition to storing locations, your class should be able to filter out duplicate loca- tions and calculate a bounding box around all locations that are stored. Your provided Java™ source code must be compatible with a collection of provided Java™ classes that implement individual lo- cations and a top-level driver for testing your "map box" implementation ored. Your provided Java™Explanation / Answer
// MapBox.java
import java.util.ArrayList;
public class MapBox {
private ArrayList<Location> locations;
public MapBox()
{
locations = new ArrayList<>(); // create a list of Location
}
public double Westmost()
{
double westMost = locations.get(0).longitude;
for(int i=1;i<locations.size();i++)
if(locations.get(i).longitude < westMost)
westMost = locations.get(i).longitude;
return westMost;
}
public double Eastmost()
{
double eastMost = locations.get(0).longitude;
for(int i=1;i<locations.size();i++)
if(locations.get(i).longitude > eastMost)
eastMost = locations.get(i).longitude;
return eastMost;
}
public double Southmost()
{
double southMost = locations.get(0).latitude;
for(int i=1;i<locations.size();i++)
if(locations.get(i).latitude < southMost)
southMost = locations.get(i).latitude;
return southMost;
}
public double Northmost()
{
double northMost = locations.get(0).latitude;
for(int i=1;i<locations.size();i++)
if(locations.get(i).latitude > northMost)
northMost = locations.get(i).latitude;
return northMost;
}
public boolean recordLocation(Location loc)
{
for(int i=0;i<locations.size();i++)
if(loc.name.equalsIgnoreCase(locations.get(i).name))
return false;
locations.add(loc);
return true;
}
}
//end of MapBox.java
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.