Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA PLEASE question 1 Write a class called Address that will represent an address. The department will contain the following features: street the name of

JAVA PLEASE
question 1
Write a class called Address that will represent an address. The department will contain the following features:
street the name of the street, of type String.
city the name of the city, of type String.
zip the zip code, type int.
Added the following constructors to the class:
public Address(String street, String city, int zip) the constructor will receive the address details and place them in the attributes. There is no need to check the validity of the parameters. It can be assumed that street and city are strings that represent street and city, and zip represents zip code.
public Address(Address other) copy constructor.
Add get/set methods to the class for each of the features and according to the writing conventions we learned.
Write the following methods in the class:
public String toString()- the method will return a string representing the address in the following format - if the address is on Herzl Street, Jerusalem zip code 1111, the method will return the string:
Herzl st., Jerusalem 1111
public boolean equals(Address other) the method will accept as a parameter an object of type Address and return true if the two addresses (the address represented by this and the address represented by other) are equal. Two addresses will read equal if they are in the same city, same street and same zip code.
public boolean isInTheSameCity(Address other) The method will receive as a parameter an object of type Address and will return true if both addresses (the address represented by this and the address represented by other) are in the same city.
Question 2
Write a class called Student that represents a student. The department will contain the following features:
name the name of the student, of type String.
studentNum student number, type int.
studentAddress the student's address, of type Address.
Add the following constructor to the class:
public Student(String name, int num, Address studentAddress) the constructor will receive the student details and place them in the attributes. Avoid aliasing! You must copy the received studentAddress parameter.
They also added a copy builder to the department.
Add get/set methods to the class for each of the attributes. Also here, avoid aliasing.
Write the following features in the class:
public String toString()- the method will return the student's information in the following format - if the student's name is Yossi, his number is 222 and his address is Herzl Street in Jerusalem, zip code 1111, the method will return the string:
Student Yossi, 222
Srudent's Address: Herzl st., Jerusalem 1111
public boolean sameAddress(Student other) the method as a Student object parameter and will return true if both students (the student represented by this and the student represented by other) live at the same address.
public boolean isInTheSameCity(Student other)- the method as an object parameter of type Student and will return true if both students (the student represented by this and the student represented by other) live in the same city.
Question 3
Write a class called WorkPlace that represents a workplace that employs students. The workplace has the following features
worker - a student working at the workplace, of type Student. Let's say that only one student works at the workplace.
workPlaceAddress the address of the workplace, of type Address
Add the following constructor to the class -
public WorkPlace(Student worker, Address workPlaceAddress) the constructor will receive two parameters and copy them to attributes (avoid aliasing).
Added get/set methods for the attributes to the class, and also prevented aliasing here.
Write the following methods in the class:
public String toString() the method will return a string representing the workplace in the following format:
Workplace at Jaffa st., Jerusalem 5454
Worker: Student Yossi, 222
Student's address: Herzl st., Jerusalem 1111
public boolean isSameAddressAsWorker() the method will return true if the workplace is at the same address where its worker lives.
public boolean isSameCityAsWorker() the method will return true if the workplace is in the same city where its worker lives.

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2019 Wurzburg Germany September 16 20 2019 Proceedings Part 2 Lnai 11907

Authors: Ulf Brefeld ,Elisa Fromont ,Andreas Hotho ,Arno Knobbe ,Marloes Maathuis ,Celine Robardet

1st Edition

3030461467, 978-3030461461

More Books

Students also viewed these Databases questions