Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help me with this Java coding activity. Thank you! Given Code======================================== public class RoadTripTester extends ConsoleProgram { public void run() { RoadTrip rt =

Please help me with this Java coding activity. Thank you!

image text in transcribedimage text in transcribedGiven Code========================================

public class RoadTripTester extends ConsoleProgram { public void run() { RoadTrip rt = new RoadTrip(); rt.addStop("San Francisco", 37.7833, -122.4167); rt.addStop("Los Angeles", 34.052235, -118.243683); rt.addStop("Las Vegas", 36.114647, -115.172813);

System.out.println(rt); System.out.println("Stops: " + rt.getNumberOfStops()); System.out.println("Total Miles: " + rt.getTripLength()); } }

/* * This class stores information about a location on Earth. Locations are * specified using latitude and longitude. The class includes a method for * computing the distance between two locations. * * This implementation is based off of the example from Stuart Reges at * the University of Washington. */

public class GeoLocation { // Earth radius in miles public static final double RADIUS = 3963.1676;

private double latitude; private double longitude;

/** * Constructs a geo location object with given latitude and longitude */ public GeoLocation(double theLatitude, double theLongitude) { latitude = theLatitude; longitude = theLongitude; }

/** * Returns the latitude of this geo location */ public double getLatitude() { return latitude; }

/** * returns the longitude of this geo location */ public double getLongitude() { return longitude; }

// returns a string representation of this geo location public String toString() { return "latitude: " + latitude + ", longitude: " + longitude; }

// returns the distance in miles between this geo location and the given // other geo location public double distanceFrom(GeoLocation other) { double lat1 = Math.toRadians(latitude); double long1 = Math.toRadians(longitude); double lat2 = Math.toRadians(other.latitude); double long2 = Math.toRadians(other.longitude); // apply the spherical law of cosines with a triangle composed of the // two locations and the north pole double theCos = Math.sin(lat1) * Math.sin(lat2) + Math.cos(lat1) * Math.cos(lat2) * Math.cos(long1 - long2); double arcLength = Math.acos(theCos); return arcLength * RADIUS; } }

import java.util.*;

public class RoadTrip { }

In this problem we are going to use ArrayLists and classes to design a road trip. You have three classes: Geolocation.java from earlier, which represents a geo location. A Roadtrip.java class which represents a road trip (or an ordered list of places), and a Roadtriptester.java class which brings them all together. In GeoLocation.java: Add a private instance variable called name which is a String. This represents the name of the location. Modify the Geolocation class constructor so that it is now of the format public GeoLocation(String name, double theLatitude, double theLongitude) Add a getter method for name called getName(). Update the toString so that it returns a String of the format San Francisco (37.7833, -122.4167) Now, you'll also need to create a Road Trip class. The Road Trip stores an ordered list of locations, so you'll need to have an ArrayList. You'll also need to support these methods. // Create a GeoLocation and add it to the road trip public void addstop(String name, double latitude, double longitude) // Get the total number of stops in the trip public int getNumberofstops() // Get the total miles of the trip public double getTripLength() // Return a formatted tostring of the trip public String toString() We've given you a tester program to help get you started. The output from that program would be: 1. San Francisco (37.7833, -122.4167) 2. Los Angeles (34.052235, -118.243683) 3. Las Vegas (36.114647, -115.172813) Stops: 3 Total Miles: 572.9708850442705

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

Step: 3

blur-text-image

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

Spatial Database Systems Design Implementation And Project Management

Authors: Albert K.W. Yeung, G. Brent Hall

1st Edition

1402053932, 978-1402053931

More Books

Students also viewed these Databases questions

Question

Explain in detail how the Mughal Empire was established in India

Answered: 1 week ago

Question

Problem: Evaluate the integral: I - -[ze dx

Answered: 1 week ago

Question

Problem: Evaluate the integral: I = 1- 1 dx 9

Answered: 1 week ago

Question

8. Providing support during instruction.

Answered: 1 week ago