Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PLEASE HELP WITH THIS ASSIGNMENT AND READ ALL INSTRUCTIONS CAREFULLY IF YOU HAVE ANY QUESTIONS FEEL FREE TO ASK I AM WILLING TO PAY EXTRA

PLEASE HELP WITH THIS ASSIGNMENT AND READ ALL INSTRUCTIONS CAREFULLY IF YOU HAVE ANY QUESTIONS FEEL FREE TO ASK I AM WILLING TO PAY EXTRA MONEY THOUGH CHEGG TUTORING TO GET THIS LAB DONE

image text in transcribed

image text in transcribed

LOCATION.JAVA

//

// Location

//

// This class implements a place on a map. Each location

// includes a textual name and a pair of Cartesian

// coordinates. Note that textual names are assumed to be

// unique; two locations are considered the same if they

// have the same name.

//

//

import java.io.*;

import java.util.*;

public class Location {

public String name = "";

public double longitude = 0.0;

public double latitude = 0.0;

// Default constructor ...

public Location() {

this.name = "";

this.longitude = 0.0;

this.latitude = 0.0;

}

// Constructor with location name specified ...

public Location(String name) {

this();

this.name = name;

}

// Constructor with location name and coordinates specified ...

public Location(String name, double longitude, double latitude) {

this(name);

this.longitude = longitude;

this.latitude = latitude;

}

// equals -- Return true if and only if this location has the same name

// as the argument location.

public boolean equals(Location loc) {

return (loc.name.equals(this.name));

}

// read -- Read a location description from the given stream into this

// object. At minimum, a name must be read from the stream. Optionally,

// coordinates may also be specified as a pair of double precision

// floating point numbers. Return true if at least a name was read and

// false otherwise.

public boolean read(BufferedReader str) {

try {

String thisLine = str.readLine();

if (thisLine == null)

// No more input, at all ...

return (false);

Scanner inScanner = new Scanner(thisLine);

inScanner.useDelimiter("\\s+");

if (inScanner.hasNext()) {

// There is something to read ...

name = inScanner.next();

if (inScanner.hasNextDouble()) {

// There is a longitude to read ...

longitude = inScanner.nextDouble();

if (inScanner.hasNextDouble()) {

// There is a latitude to read ...

latitude = inScanner.nextDouble();

}

}

inScanner.close();

// At least a name was successfully read ...

return (true);

} else {

inScanner.close();

// Did not even read a name ...

return (false);

}

} catch (IOException e) {

// Something went wrong ...

return (false);

}

}

// write -- Write the name of this location to the given stream. If the

// "showCoords" argument is true, then also output the Cartesian

// coordinates of this location, separated by blanks, on the same line.

public void write(OutputStream str, boolean showCoords) {

PrintWriter out = new PrintWriter(str, true);

out.printf("%s", name);

if (showCoords) {

out.printf(" %f %f", longitude, latitude);

}

}

}

EZERO.JAVA

//

// Ezero

//

// This class provides a "main" method that acts as a driver program

// for evaluating bounding box implementations. A file of locations,

// consisting of names and coordinate pairs, is read. If a location

// name is duplicated in the list, the first location is recorded

// and the duplicate discarded. The name of the duplicate location

// is reported. The bounding box that surrounds all read locations

// is then output, and this is followed by the output of all of

// the locations, with no duplicates listed. Program output is

// written to the standard output stream.

//

//

import java.io.*;

public class Ezero {

public static void main(String[] args) {

MapBox map = new MapBox();

String locationFilename = "locations.dat";

System.out.println("BOUNDING BOX TEST");

System.out.flush();

// Read the locations into the allocated MapBox object ...

try {

// Open file of locations ...

File locFile = new File(locationFilename);

if (locFile.exists() && locFile.canRead()) {

// Convert File to a BufferedReader ...

FileInputStream locFileIn = new FileInputStream(locFile);

InputStreamReader locISReader = new InputStreamReader(locFileIn);

BufferedReader locBufferedReader = new BufferedReader(locISReader);

// Read all of the locations in the file into the

// allocted MapBox object. First, allocate storage

// for the first location to be read ...

Location loc = new Location();

// Read one location at a time ...

while (loc.read(locBufferedReader)) {

// Record location in the MapBox object ...

if (!(map.recordLocation(loc))) {

// A false return value from "recordLocation"

// means that the location is a duplicate.

System.out.printf("Duplicate Location: %s ", loc.name);

} else {

// Allocate storage for the next location ...

loc = new Location();

}

}

// Output results ...

// Output size of bounding box ...

System.out.println("The Bounding Box:");

System.out.printf(" West Edge = %f ", map.Westmost());

System.out.printf(" East Edge = %f ", map.Eastmost());

System.out.printf(" North Edge = %f ", map.Northmost());

System.out.printf(" South Edge = %f ", map.Southmost());

System.out.println("The Locations:");

for (Location outloc : map.locations) {

outloc.write(System.out, true);

System.out.println("");

}

} else {

System.err.println("ERROR: Could not open file for reading.");

}

} catch (IOException e) {

// Something went wrong ...

System.err.println("ERROR: IO exception thrown.");

}

// Done ...

System.out.println("BOUNDING BOX TEST COMPLETE");

}

}

You are to provide a Java 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 JavaM 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. Your exercise solution will be evaluated by combining your submitted class file with copies of the provided utility class files and testing the resulting complete program against a variety of test cases. In other words, your solutionmust work with the provided utilities, without any modifications to these provided files 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 e 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 JavaTM 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 include: . Location_This object encodes a location on the map. It includes a location name, a longitude (x-axis coordinate), and a latitude (y-axis coordinate)

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_2

Step: 3

blur-text-image_3

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

More Books

Students also viewed these Databases questions