Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

java please Activities Implement the compareTo ( ) method in the Location class. You may use whatever criteria you wish ( city / state or

java please
Activities
Implement the compareTo() method in the Location class. You may use whatever criteria you wish
(city/state or latitude/longitude etc.).
Implement the insertionSort() and quickSortRecursive() methods in the SortingAlgorithms class. Do
this by adapting the algorithms as presented in your text book or other resource (algorithms are also available
in our CS1 textbook.
package unl.cse.sorting;
public class Location implements Comparable {
private final String zipCode;
private final String city;
private final Double latitude;
private final Double longitude;
private final String state;
public Location(String zipCode, Double latitude, Double longitude, String city, String state){
this.zipCode = zipCode;
this.city = city;
this.latitude = latitude;
this.longitude = longitude;
this.state = state;
}
public String getCity(){
return this.city;
}
public String getZipCode(){
return this.zipCode;
}
public Double getLatitude(){
return latitude;
}
public Double getLongitude(){
return longitude;
}
public String getState(){
return state;
}
/**
* Complete the implementation of this method that will be used for sorting
* collections of Locations.
*
* @param l
* @return
*/
@Override
public int compareTo(Location l){
throw new UnsupportedOperationException("YOU MUST IMPLEMENT THIS");
}
@Override
public String toString(){
StringBuilder sb = new StringBuilder();
sb.append(this.getCity());
sb.append("");
sb.append(this.getState());
sb.append(",");
sb.append(this.getZipCode());
return sb.toString();
}
@Override
public boolean equals(Object obj){
return (obj != null && obj instanceof Location)?(this.compareTo((Location) obj)==0) : false;
}
@Override
public int hashCode(){
final int prime =31;
int result =1;
result = prime * result +((city == null)?0 : city.hashCode());
result = prime * result +((latitude == null)?0 : latitude.hashCode());
result = prime * result +((longitude == null)?0 : longitude.hashCode());
result = prime * result +((state == null)?0 : state.hashCode());
result = prime * result +((zipCode == null)?0 : zipCode.hashCode());
return result;
}
}
image text in transcribed

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

Advanced Database Systems For Integration Of Media And User Environments 98

Authors: Yahiko Kambayashi, Akifumi Makinouchi, Shunsuke Uemura, Katsumi Tanaka, Yoshifumi Masunaga

1st Edition

9810234368, 978-9810234362

More Books

Students also viewed these Databases questions