100% found this document useful (1 vote)
21 views2 pages

EX03

The document describes an exercise to create two Java classes - Address and Person. Address represents an address with fields for street, city and zip code. Person represents a person with a name and address. The classes should have get/set methods and constructors as described. A tester class is also to be created to initialize and print sample objects, and check if two people live in the same city.

Uploaded by

mo2419270
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
21 views2 pages

EX03

The document describes an exercise to create two Java classes - Address and Person. Address represents an address with fields for street, city and zip code. Person represents a person with a name and address. The classes should have get/set methods and constructors as described. A tester class is also to be created to initialize and print sample objects, and check if two people live in the same city.

Uploaded by

mo2419270
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Advanced Programming (0303204/0303208)

EX03:
A) Write a class named Address.java that represents an address with the
following fields and methods with suitable access modifiers:
Two string fields for street and city, an integer field for zip code.
The Address class has the following methods:
1. Address(String street, String city, int zip): assigns the parameters to
the class data fields.
2. Address( Address D) : a copy constructor.
3. getStreet() : returns the street value
4. getCity(): returns the city value.
5. getZip(): returns the zip value.
6. toString(): returns a string of the Address object in the following form:
street. City, zip
example:
Wadeljoz. Jerusalem, 1234
7. isSameCity(Address a): returns true if this Address object and a object
has same city.
B)Write another class named Person.java that has the following:
1. A string field name.
2. An Address field add.
Class Person has the following methods:
1. Person(String name, Address add) : assigns the parameters to the class
data fields.
2. Person(String name, String street, String city, int zip): assigns the
parameters to the class data fields.
3. getName(): return the name of person.
4. getAddress(): returns the address of person.
5. setAddress(Address add): assigns the parameter to the this object
Address.
6. toString(): returns a string in the following form:
Person name: Ahmad
Address: Wadeljoz. Jerusalem, 1234
7. LiveInTheSameCity(Person p): returns true if Person object p has the
same city value of this Person object.
2
a) Write a tester class Test.java that initialize and print Address and
Person objects for Saeed Halawany who lives in (Wadeljoz,
Jerusalem, 1234), examine and output if Saeed lives in the same city
where you live.
Submission Guidelines
1. Submit this exercise individually
2. The classes are bagged in a zip or rar file single, called Ex3.zip or Ex3.rar.

You might also like