Question
need help with the bottom screenshots please i will include all the other codes below public class Location { private static final double EARTH_RADIUS_MILES =
need help with the bottom screenshots please
i will include all the other codes below
public class Location { private static final double EARTH_RADIUS_MILES = 3963.1676; private double latitude; private double longitude; public Location() { this.latitude = 0; this.longitude = 0; } public Location(double lat, double lon) { this.latitude = lat; this.longitude = lon; } public double getLatitude() { return latitude; } public double getLongitude() { return longitude; } public void setLatitude(double lat) { this.latitude = lat; } public void setLongitude(double lon) { this.longitude = lon; } public double distanceFrom(Location other) { double lat1 = Math.toRadians(this.getLatitude()); double lon1 = Math.toRadians(this.getLongitude()); double lat2 = Math.toRadians(other.getLatitude()); double lon2 = Math.toRadians(other.getLongitude()); double cosC = Math.sin(lat1) * Math.sin(lat2) + Math.cos(lat1) * Math.cos(lat2) * Math.cos(lon1 - lon2); double arcLenC = Math.acos(cosC); return arcLenC; } }
Place.java
public class Place {
private String name;
private String description;
private Location location;
//Place(name : String, desc : String, latitude : double, longitude : double)
public Place(String name, String desc, double latitude, double longitude){
this.name = name;
this.description = desc;
this.location = new Location(latitude, longitude);
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Location getLocation() {
return location;
}
public void setLocation(Location location) {
this.location = location;
}
public void setLocation(double latitude, double longitude) {
this.location = new Location(latitude, longitude);
}
public String getIdentificationString(){
return this.name + "," + this.description + "," + this.location.toString();
}
public String toString(){
return getIdentificationString();
}
}
public class Attraction extends Place { private int type; private double price;
public Attraction() {
}
public Attraction(String name, String desc, double latitude, double longitude, double price, int type) { super(name, desc, latitude, longitude); this.type = type; this.price = price; }
public int getType() { return type; }
public void setType(int type) { this.type = type; }
public double getPrice() { return price; }
public void setPrice(double price) { this.price = price; }
public boolean hasAnimals() { if (this.type == 1 || this.type == 2) { return true; } return false; }
@Override public String toString() { if (this.hasAnimals()) return super.toString() + " \t Tickets average $" + this.price + " and feature exciting animals"; else return super.toString() + " \t Tickets average $" + this.price; }
}
public class Eatery extends Place { private double cost; private String cuisine; private int starRating;
public Eatery(String name, String desc, double latitude, double longitude, String cuisine, double cost, int starRating) { super(name, desc, latitude, longitude); this.cost = cost; this.cuisine = cuisine; this.starRating = starRating; }
public double getCost() { return cost; }
public void setCost(double cost) { this.cost = cost; }
public String getCuisine() { return cuisine; }
public void setCuisine(String cuisine) { this.cuisine = cuisine; }
public int getStarRating() { return starRating; }
public void setStarRating(int starRating) { this.starRating = starRating; }
public String ratingToStars() { String s = ""; for (int i = 0; i
public String getCostSymbols() { if (cost 25.0 && cost 50.0 && cost 75.0 && cost
@Override public String toString() { return super.toString() + " \t Price: " + this.getCostSymbols()+" \t Rating: "+this.ratingToStars(); } }
Instructions for Destinations.java Using the template provided below, write a driver class Destinations.java that performs the ToDo tasks in the order indicated Your code will be tested for output and additional unit tests will be performed Include, but do not call, getldentificationString0 that returns Program 5a, Firstname Lastname Tips: An ArrayList type is indexed but instead of using braces such as myArrayList[01, we use a method myArrayList.get() Methods can be strung together" with the dot operator. For example, places.get(0) returns a Place object for index 0 (the Original Pancake House Eatery object) places.get(O) getName0 returns a Place object then for that object calls its getNameO resulting in a String object "Original Pancake House" places.get(0) getName0.equals(Phil's BBQ") tests this Place object's name against Phil's BBQ" resulting in false Don't rewrite code! If a method exists to perform the task you need, use it! Casting (oh, my!) We have an ArrayList of Place objects. Now, recall this parent class can be a reference to its subclasses. So why can't we write this? System.out.println (places.get (O).getName))1/ This works System.out.println (places.get (0).getCuisine))11 This doesn't work! getName) is a method in the superclass Place. So the object at index 0 is-a Place (a Eatery is-a Place) and the superclass method getName0 is inherited. Yay! getCuisine(), however, is a method in the subclass Eatery. A Place is not necessarily an Eatery, that is, it could be an Attraction or a Place. The compiler cannot guarantee that the getcuisine) method exists, so it indicates an error at compile time. The solution is to cast the retrieved object to the subclass that contains the method. Eatery pancake-(Eatery)places.get (0) System.out.printin (pancake.getCuisine ))Step 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