Question: Instructions for Attraction.java Write a Java program Attraction.java that has the following characteristics. extends Place New attributes: type (int) price (double) New Methods: public Attraction(String

Instructions for Attraction.java

Write a Java program Attraction.java that has the following characteristics.

extends Place

New attributes:

type (int)

price (double)

New Methods:

public Attraction(String name, String desc, double latitude, double longitude, double price, int type) where for type values: - 0 is an amusement park - 1 is an aquarium - 2 is a zoo

public double getPrice() -- returns current price

public int getType() -- returns type

public boolean hasAnimals() -- returns true if type contains "zoo" or "aquarium"

public String toString() -- overrides superclass toString() method so that: - second line: print tab character, "Tickets average $xx.xx" and, if hasAnimals() is true, "and feature exciting animals". Examples:

Seaport Village (latitude:32.70872,longitude:-117.171) Tickets average $55.00 San Diego Zoo (latitude:32.73607,longitude:-117.14927) Tickets average $55.00 and feature exciting animals 

Instructions for Eatery.java

Write a Java program Eatery.java that has the following characteristics:

extends Place

New attributes:

cost (double)

cuisine (String)

starRating (int)

New Methods:

public Eatery(String name, String desc, double latitude, double longitude, String cuisine, double cost, int starRating)

public double getCost() -- returns current cost

public String getCuisine() -- returns current cuisine

public int getRating() -- returns current starRating

public String ratingToStars() -- returns string containing one '*' character for each value (1 to 5)

public String getCostToSymbols() -- returns '$' characters that correspond to cost [Note: no spaces--ZyBooks MarkDown text doesn't allow four dollar signs in a row. Grrr! ] - if cost is less than 25.0, $ - if cost is less than 50.0, $$ - if cost is less than 75.0, $$$ - if cost is less than 100.0, $$ $$ - if cost is greater than or equal to 100.0, $$ $$+

public String toString() -- overrides superclass toString() method so that: - second line: print tab character, "Price: $xxx" where xxx corresponds to cost - third line: print tab character, print "Rating: *xxx" where xxx corresponds to starRating

The Cottage Restaurant (latitude:32.84341,longitude:-117.275) Price: $$$$ Rating: **** 

***********

THIS PART IS FOR REFERENCE

-------------------------------------- Location -------------------------------------- - EARTH_RADIUS_MILES : double = 3963.1676 - latitude : double - longitude : double -------------------------------------- + Location() + Location(lat : double, lon : double) + setLatitude(lat : double) : void + getLatitude() : double + setLongitude(lon : double) : void + getLongitude() : double + distanceFrom( o : Location) : double --------------------------------------

Coding distanceFrom()

The distance from one location to another can be found by the Spherical Law of Cosines.

Let point x be latitude1, longitude1 and point y be latitude2, longitude2. Then:

cosC = sin(latitude1) * sin(latitude2) + cos(latitude1) * cos(latitude2) * cos(longitude1-longitude2)

arcLenC = acos(cosC)

Now, using the Math class, we can plug in our formula (where point x is this location and point y is the other location provided as the method parameter).

 // Returns the distance in miles between this geo location and the given // other geo location public double distanceFrom(Location other) { // TODO: First use Math.toRadians() convert this latitude & longitude, and // the other latitude & longitude to radians double lat1 = double lon1 = double lat2 = double lon2 = // TODO: Apply the spherical law of cosines with a triangle composed of // the two locations and the North Pole double cosC = double arcLenC = // Return the arcLenC times RADIUS } 

Testing

Writing a program to test your code is a common practice. YOU WILL NOT TURN THE TEST PROGRAM IN! A simple way to do this is to open another file, called TestLocation (or whatever), write a main() method that

instantiates a Location object using the no-arg constructor

print getLatitude() and getLongitude() return values (should be zeros)

call the setters

print again to show values were modified to whatever values you passed in

repeat Steps 1 - 4 but use the Location two-arg constructor

end part 1

part 2

------------------------------------------------------------------------ Place ------------------------------------------------------------------------ - name: String - description : String - location : Location ------------------------------------------------------------------------ + Place(name : String, desc : String, latitude : double, longitude : double) + setName(name : String) : void + getName() : String + setDescription(desc : String) : void + getDescription() : String + setLocation( latitude : double, longitude : double) : void + setLocation( location : Location) : void + getLocation() : Location + toString() : String + getIdentificationString() : String ------------------------------------------------------------------------

A call to print a Place object System.out.println(myPlaceObject); should return a string of the format:

San Diego Zoo,2920 Zoo Drive,latitude:32.735316,longitude:117.149046 

Location.java Instructions

Retrieve the Location.java class from Prog4a. Keeping all methods and structure, add the two methods described below.

---------------------------------- Location ---------------------------------- + equals( o : Location) : boolean + toString() : String --------------------------------------------------------- A call to print a Location object System.out.println(myLocationObject); should return a string of the format:

latitude:32.735316,longitude:-117.149046 

A call to determine if two Location objects are equal System.out.println(myLocationObject.equals(someOtherLocationObject); will return true if the latitude and longitude are the same (within 0.0001 degrees difference). Therefore, if:

loc1 is at latitude: 32.735316,longitude: -117.149046 loc2 is at latitude: 32.735328,longitude: -117.14910 loc3 is at latitude: 32.735328,longitude: -117.14920

loc1 is equal to loc2

since absolute value of the difference of latitudes is less than 0.0001 and same goes for longitudes

loc1 is not equal to loc3

though absolute value of the difference of latitudes is less than 0.0001, longitudes are greater than 0.0001 difference

Testing

Writing a program to test your code is a common practice. YOU WILL NOT TURN THE TEST PROGRAM IN! A simple way to do this is to open another file, called TestPlace, write a main() method that:

instantiates a Place object using the constructor

print the "getters" and verify data is accurate

call the setters

print again to show values were modified to whatever values just set

repeat Steps 1 - 4 but use different data, possibly something that might cause an error

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!