Advertisement
butoff

PersonClass

Dec 5th, 2018
538
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.14 KB | None | 0 0
  1. import java.util.ArrayList;
  2.  
  3. public class Person {
  4.  
  5.     private int id;
  6.     private String name;
  7.     private String phone;
  8.     private int age;
  9.     private ArrayList<Person> friendList;
  10.  
  11.     public Person(int id, String name, String phone, int age) {
  12.         this.id = id;
  13.         this.name = name;
  14.         this.phone = phone;
  15.         this.age = age;
  16.         this.friendList = new ArrayList<>();
  17.     }
  18.  
  19.     public int getId(){
  20.         return  this.id;
  21.     }
  22.     public String getName(){
  23.         return  this.name;
  24.     }
  25.  
  26.     public void addFriend(Person person){
  27.         this.friendList.add(person);
  28.     }
  29.  
  30.     public void introducePerson() {
  31.         System.out.printf("Hey, I am %s and I am %d yers old :)\n", this.name, this.age);
  32.     }
  33.  
  34.     public void sharePhone() {
  35.         System.out.printf("You can contact me at %s\n", this.phone);
  36.     }
  37.  
  38.     public void showFriends() {
  39.         System.out.print("My friends are: ");
  40.  
  41.         for (int f = 0; f < friendList.size(); f++) {
  42.  
  43.             Person currentPerson = friendList.get(f);
  44.  
  45.             System.out.printf("%s ", currentPerson.getName());
  46.         }
  47.     }
  48.  
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement