Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

AddressTester.java below 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,

AddressTester.java below

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");
}
}



Address.java below

/**
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. We will study the inherited equals method in class this week



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




P.S: Please include a screenshot of the output. Thank you

A class to keep track of, print, and compare addresses with and without apartment numbers. Run the program AddressTester.java which generates a list of Address objects and then searches this list for a given address. You will add code to *both* Address.java and to AddressTester.java (see the comments) See the following files: * AddressTester.java (has todo) * Address.java (has todo) Approximate total lines of code required: 7

Step by Step Solution

There are 3 Steps involved in it

Step: 1

AddressTesterjava import javautilArrayList public class AddressTester public static void mainString args ArrayList addresses new ArrayList addressesaddnew Address314Yonge StreetTorontoONM5B 2K3 addres... 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

Java Programming

Authors: Joyce Farrell

9th edition

1337397075, 978-1337397070

More Books

Students also viewed these Programming questions