Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

/** A class to keep track of, print, and compare addresses with and without apartment numbers. */ public class Address { private String streetNumber; private

/** A class to keep track of, print, and compare addresses with and without apartment numbers. */ public class Address { private String streetNumber; private String apartment; private String street; private String city; private String province; private String postalCode;

/** Constructs an address with everything but an apartment number. @param streetNumber the house number as a string @param street the street as a string @param city the city as a string @param state the state as a string @param postalCode the postal code as a string

*/ public Address(String streetNumber, String street, String city, String province, String postalCode) { this.streetNumber = streetNumber; this.apartment = ""; this.street = street; this.city = city; this.province = province; this.postalCode = postalCode; }

/** Constructs an address with an apartment number @param streetNumber the house number as a string @param apartment the apartment number as a string @param street the street as a string @param city the city as a string @param state the state as a string @param postalCode the postal code as a string */ public Address(String streetNumber, String apartment, String street, String city, String province, String postalCode) { this.streetNumber = streetNumber; this.apartment = apartment; this.street = street; this.city = city; this.province = province; this.postalCode = postalCode; }

public String toString() { return "[" + streetNumber + " " + street + " " + apartment + city + ", " + province + " " + postalCode + "]"; }

/** Compares two addresses by first comparing province, then city, street, streetNumber, apartment This method must have the given signature as it is inherited from superclass Object @param other the other address @return true if the addresses are equal, false otherwise */ public boolean equals(Object other) { Address otherA = (Address) other; //-----------Start below here. To do: approximate lines of code = 3 // compare the province, city, street, streetNumber, and apartment of this address and the other address otherA. If all are equal, return true // else return false.

//-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions. } }

import java.util.ArrayList; public class AddressTester { public static void main(String[] args) { ArrayList

addresses = new ArrayList();

addresses.add(new Address("314", "Yonge Street", "Toronto", "ON", "M5B 2K3")); addresses.add(new Address("13", "Jarvis Street", "Toronto", "ON", "M4X 1H1")); addresses.add(new Address("26", "Avenue Road", "Toronto", "ON", "M5C 2H4")); addresses.add(new Address("67", "Bay Street", "Toronto", "ON", "M5X 2B1")); addresses.add(new Address("314", "Yonge Street", "Toronto", "ON", "M5B 2K3")); addresses.add(new Address("666", "501", "Spadina Avenue", "Toronto", "ON", "M53 2K3"));

Address addr = new Address("26", "Avenue Road", "Toronto", "ON", "M5C 2H4");

boolean found = false; //-----------Start below here. To do: approximate lines of code = 4 // search through the list of adddresses to see if Address addr is in there. // If so , set found = true and break

//-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions. if (found) { System.out.println(addr.toString() + " is in the list of addresses"); } else { System.out.println(addr.toString() + " is not in the list of addresses"); } System.out.println("Expected: " + addr.toString() + " is in the list of addresses"); } }

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_2

Step: 3

blur-text-image_3

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 Fundamentals Study Guide

Authors: Dr. Sergio Pisano

1st Edition

B09K1WW84J, 979-8985115307

More Books

Students also viewed these Databases questions