Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a binary search method (in a class called BinarySearch) that searches for a city by name and returns the City object if found. Create

Write a binary search method (in a class called BinarySearch) that searches for a city by name and returns the City object if found. Create a sample try with two cities from each Canadian province. A file, City.java, is given to help:

public class City implements Comparable { private static String [] PROVINCE_CODE = {"BC", "AB", "SK", "MB", "ON", "QC", "NB", "NS", "PE", "NL", "YT", "NT", "NU"}; private String name; private int population; private String province;

public City (String name, String province, int population) { setName(name); setProvince(province); setPopulation(population); }

public String getName() { return name; } public void setName(String name) { this.name = name; } public int getPopulation() { return population; } public void setPopulation(int population) { if (population < 0) { this.population = 0; } else { this.population = population; } } public String getProvince() { return province; } public void setProvince(String province) { this.province = province; }

public String toString() { return (this.name + ", " + this.province); }

@Override public int compareTo(City otherCity) { return (this.toString().compareTo(otherCity.toString())); }

}

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

Database Processing Fundamentals, Design, and Implementation

Authors: David M. Kroenke, David J. Auer

14th edition

133876705, 9781292107639, 1292107634, 978-0133876703

More Books

Students also viewed these Databases questions

Question

What must a creditor do to become a secured party?

Answered: 1 week ago

Question

When should the last word in a title be capitalized?

Answered: 1 week ago

Question

Provide examples of Dimensional Tables.

Answered: 1 week ago