Question: n 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

n 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, youll also need to create a RoadTrip class. The RoadTrip stores an ordered list of locations, so youll need to have an ArrayList. Youll 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()

Weve 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

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()); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!