program with the goal of creating a hierarchy of classes that will serve as the
ID: 3538290 • Letter: P
Question
program with the goal of creating a hierarchy of classes that will serve as the
templates for creating various address book contact objects and in doing so
demonstrate knowledge of the Object Oriented Programming practices. There is no
single correct way to organize the class hierarchy, that said, I do not
want to see a large group of totally unrelated classes or a situation where all
the classes directly inherit from a single superclass. It is important to
make a list of the required attributes and think about which are shared and
which are not. A correct project will have a series of classes in an
inheritance hierarchy with a depth of approx. 3 to 4 classes.
Classes:At a minimum allow for your program to allow objects to be
instantiated from the following classes (you are encouraged to create super
classes as needed):
should contain the appropriate attributes from the following list:
properties or attributes private and include setXAttribute and getXAttribute
methods. Also include constructors and toString methods as needed. The toString
methods should return a well styled String for all of the contact records
properties. Each class should contain two constructors, a default constructor
that takes no arguments and a fully parameterized constructor which has
arguments for all of the properties in that class. Additionally, use an
interface to implement a method called "tweets." The tweets method should simply
return a boolean.
toString will need to account for both the individual and the business too)
Family
Create a simple class with a main method to handle testing the above classes.
The main method needs to create two each of the above non-abstract classes (just
hard code in the values) and store all of the objects in a single array.
After the all of the objects have been created, loop through the array printing
each contact to the command line. Finally create another array of only those
objects that implement %u201Ctweets.%u201D Also loop through this array printing out the
values to the command line.
Explanation / Answer
Sample output
Printing all the objects
Business [name=Google, email=google@gmail.com, address=California, website=www.google.com, phone=1222344334, tweets()=true]
Business [name=Oracle, email=oracle@gmail.com, address=London, website=www.oracle.com, phone=4383828423, tweets()=true]
Friend [name=Richard Anderson, first_name=Richard, last_name=Anderson, phone=39229232, email=richie@gmail.com, address=Los angles. Street No. 2, tweets()=true]
Friend [name=James Willy, first_name=James, last_name=Willy, phone=37462833, email=james@gmail.com, address=Boston, tweets()=true]
Family [name=Mark Benson, first_name=Mark, last_name=Benson, phone=238423738, email=mark@gmail.com, address=new York, relationship=Brother]
Family [name=Julie Benson, first_name=Julie, last_name=Benson, phone=363823672, email=julie@gmail.com, address=new York, relationship=Sister]
Professional [name=Mark Zuckerberg, first_name=Mark, last_name=ZuckerBerg, phone=26326273, email=mark@facebook.com, address=Australia, Works for=Business [name=Google, email=google@gmail.com, address=California, website=www.google.com, phone=1222344334, tweets()=true]]
Professional [name=Angelina Jolie, first_name=Angelina, last_name=Jolie, phone=463727463, email=angelina@gmail.com, address=USA, Works for=Business [name=Oracle, email=oracle@gmail.com, address=London, website=www.oracle.com, phone=4383828423, tweets()=true]]
Printing those objects which implements tweets
Business [name=Google, email=google@gmail.com, address=California, website=www.google.com, phone=1222344334, tweets()=true]
Business [name=Oracle, email=oracle@gmail.com, address=London, website=www.oracle.com, phone=4383828423, tweets()=true]
Friend [name=Richard Anderson, first_name=Richard, last_name=Anderson, phone=39229232, email=richie@gmail.com, address=Los angles. Street No. 2, tweets()=true]
Friend [name=James Willy, first_name=James, last_name=Willy, phone=37462833, email=james@gmail.com, address=Boston, tweets()=true]
Professional [name=Mark Zuckerberg, first_name=Mark, last_name=ZuckerBerg, phone=26326273, email=mark@facebook.com, address=Australia, Works for=Business [name=Google, email=google@gmail.com, address=California, website=www.google.com, phone=1222344334, tweets()=true]]
Professional [name=Angelina Jolie, first_name=Angelina, last_name=Jolie, phone=463727463, email=angelina@gmail.com, address=USA, Works for=Business [name=Oracle, email=oracle@gmail.com, address=London, website=www.oracle.com, phone=4383828423, tweets()=true]]
public class Business implements Tweets {
private String name;
private String email;
private String address;
private String website;
private String phone;
//default constructor
public Business() {
super();
}
// Parametrized constructor
public Business(String name, String email, String address, String website,
String phone) {
super();
this.name = name;
this.email = email;
this.address = address;
this.website = website;
this.phone = phone;
}
// getter methods
public String getName() {
return name;
}
// setter methods
public void setName(String name) {
this.name = name;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getWebsite() {
return website;
}
public void setWebsite(String website) {
this.website = website;
}
// toString method
@Override
public String toString() {
return "Business [name=" + name + ", email=" + email + ", address="
+ address + ", website=" + website + ", phone=" + phone
+ ", tweets()=" + tweets() + "]";
}
// applying method from interface
public boolean tweets() {
return true;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.