Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class AddressBook{
- private Person[] entry;
- private static int count;
- AddressBook(){
- }
- AddressBook(int i){
- entry=new Person[i];
- }
- public void addPerson(Person p){
- entry[count]=p;
- count++;
- }
- public void displayAddressBook(){
- for(int i=0;i<count;i++)
- entry[i].get();
- }
- }
- class Person{
- protected String name,phone;
- protected Address addr;
- public Person(){
- }
- public Person(String s1,String s2){
- this.name=s1;
- this.phone=s2;
- }
- public Person(String s1,String s2,Address a){
- this.name=s1;
- this.phone=s2;
- this.addr=a;
- }
- public void setName(String s){
- this.name=s;
- }
- public void setPhone(String s){
- this.phone=s;
- }
- public String getName(){
- return name;
- }
- public String getPhone(){
- return phone;
- }
- public void get(){
- System.out.println("Name :"+this.getName());
- System.out.println("Phone :"+this.getPhone());
- }
- }
- class Address{
- protected String street,city,state;
- public Address(){
- }
- public Address(String s1,String s2,String s3){
- this.street=s1;
- this.city=s2;
- this.state=s3;
- }
- public String getFullAddress(){
- return this.street+'\n'+this.city+'\n'+this.state;
- }
- }
- class BussinessAssociate extends Person{
- private String jobtitle,companyName;
- public BussinessAssociate(){}
- public BussinessAssociate(String s1,String s2,Address a,String s3,String s4){
- super(s1,s2,a);
- this.jobtitle=s3;
- this.companyName=s4;
- }
- public String getJobTitle(){
- return jobtitle;
- }
- public String getCompanyName(){
- return companyName;
- }
- public void dispBusinessAssociates(){
- super.get();
- System.out.println("Job title :"+this.jobtitle);
- System.out.println("Company name :"+this.companyName);
- }
- public void get(){
- super.get();
- this.dispBusinessAssociates();
- }
- }
- class PersonalFriend extends Person{
- private String message;
- public PersonalFriend(){
- }
- public PersonalFriend(String s1,String s2,Address a,String s3){
- super(s1,s2,a);
- this.message=s3;
- }
- public String getMessage(){
- return message;
- }
- public void disPersonalFriend(){
- super.get();
- System.out.println("Message :"+this.message);
- }
- public void get(){this.disPersonalFriend();}
- }
- public class AddressBookApp{
- public static void main(String[] a){
- AddressBook book1=new AddressBook(10);
- Address ad1=new Address("No 2 Jalan Mawar","Skudai","Johor Bahru");
- Address ad2=new Address("202-2 Jalan Bendahara","Muar","Johor");
- Address ad3=new Address("111-3 Jalan Duku","Muar","Johor");
- Person newfriend1 =new Person("Ms.X","555-1212",ad1);
- book1.addPerson(newfriend1);
- BussinessAssociate b1;
- b1=new BussinessAssociate("Mr. Yeo","019-2342",ad2,"General Manager","Motorola");
- book1.addPerson(b1);
- PersonalFriend f1=new PersonalFriend("Mrs. Zyda","012-8278",ad3,"My school mate");
- book1.addPerson(f1);
- book1.displayAddressBook();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement