Question
Path.java public class Path { /* YOU PROBABLY NEED TO ADD CODE HERE */ /* YOU MUST USE A LINKED LIST! */ // Create an
Path.java
public class Path {
/* YOU PROBABLY NEED TO ADD CODE HERE */ /* YOU MUST USE A LINKED LIST! */ // Create an empty path /* YOU MAY MODIFY THIS CONSTRUCTOR */ public Path() { }
// Return a string representation of this path // Concats coordinate toString() + " " for each coordinate in path. // See Bottom of Question Page 3 for details. public String toString() { StringBuilder sb = new StringBuilder(); /* ADD CODE HERE TO BUILD STRING */ return sb.toString(); }
// Insert waypoint at the end of the path public void addWaypoint(Coordinate coord) { /* ADD CODE HERE TO ADD A COORDINATE TO THE END OF PATH */ /* YOU MUST USE A LINKED LIST! */ }
// Return Stats object recording the path statistics /* TIP: Do not work on (2) below until you have completed AND TESTED (1) */ public Stats computeStats(int altThresh) { int points = 0; double distance = 0.0; double high = 0.0; double low = 0.0;
/* (1) ADD CODE HERE TO COMPUTE THE ABOVE STATS */
double total_ascent = 0.0; double total_descent = 0.0;
/* (2) ADD CODE HERE TO COMPUTE total_ascent AND total_descent */
return new Stats(points, distance, high, low, total_ascent, total_descent); }
// Read in zero or more coordinates and either // print the path or print statistics. /* MAIN IS DONE FOR YOU! */ /* DO NOT CHANGE MAIN! */ public static void main(String[] args) { Path path = new Path(); while(!StdIn.isEmpty()) { double lon = StdIn.readDouble(); double lat = StdIn.readDouble(); double alt = StdIn.readDouble(); path.addWaypoint(new Coordinate(lon, lat, alt)); } if (args.length == 0) { StdOut.print(path); return; } else if (args.length == 1) { int thresh = Integer.parseInt(args[0]); StdOut.print(path.computeStats(thresh)); return; } StdOut.println("ERROR: Path takes zero or one command line argument."); } } *********************************************************************
Stats.java
*********************************************************************
Coordinate.java
public class Coordinate { private static final int EARTH_RADIUS = 6371000;
private double lon; private double lat; private double alt;
public Coordinate(double longitude, double latitude, double altitude) { this.lon = longitude; this.lat = latitude; this.alt = altitude; }
public double getLon() { return this.lon; }
public double getLat() { return this.lat; }
public double getAlt() { return this.alt; }
public String toString() { return this.lon + "," + this.lat + "," + this.alt; }
public double haversineDist(Coordinate that) { double lon = that.getLon(); double lat = that.getLat();
double dLat = Math.toRadians(lat - this.lat); double dLon = Math.toRadians(lon - this.lon); double a = Math.sin(dLat / 2.0) * Math.sin(dLat / 2.0) + Math.cos(Math.toRadians(this.lat)) * Math.cos(Math.toRadians(lat)) * Math.sin(dLon / 2.0) * Math.sin(dLon / 2.0); double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); return EARTH_RADIUS * c; }
public static String KMLHeader() { return "
public static String KMLFooter() { return ""; } } *********************************************************************
COS126Walk.txt
The DavidHike file and the NickMarathon file are a bunch of data and cannot fit in here
Please ask questions if have any
Problem: Compute Geographical Path Statistics. Complete the given Path. java file so that it meets the specifications below. The main method is done for you and must not be modified. Use the given Coordinate. java and Stats.java without modification. Input Specification. The input from standard input consists of zero or more lines with three doubles per line separated by a space. Each line is a geographical Earth coordinate: a longitude in decimal degrees, a latitude in decimal degrees, and an altitude in meters. These coordinates together represent a path from the first coordinate to the last coordinate. The file COS126Walk.txt contains two coordinates: the location of McCosh 10, the start point of the path, and the location of the CS Building, the end point of the path. For each line in the input, the given main method reads the coordinates, creates a Coordinate object (defined in Coordinate.java), and calls your addWaypoint method to add the coordinate to the path object (created initially by a call to the constructor). Your addWaypoint method must add the Coordinate objects to a linked list of your own design. As described below, program behavior changes depending on the presence of an optional integer command line argument. Your program need not handle non-conforming inputs. Output Specification Without Command Line Argument. If no command line argument is provided, main prints the path using a call to the Path . toString method that you must implement. For each coordinate in the path, your Path.toString method should include the result of calling Coordinate.toString on that coordinate followed by a newline. (If the path is empty, print nothing.) Example output: \% java-introcs Path 74,65708,40.348197,66.0 74.65225,40.350259,57.0 Output Specification With Command Line Argument. If invoked with an integer command line argument (an altitude threshold described below), main prints path statistics computed by calling your Path.java computeStats method. The output for COS126Walk.txt is: Altitude Threshold Points: java-introcs Path 1Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started