Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- public class Person {
- private int id;
- private String name;
- private String phone;
- private int age;
- private ArrayList<Person> friendList;
- public Person(int id, String name, String phone, int age) {
- this.id = id;
- this.name = name;
- this.phone = phone;
- this.age = age;
- this.friendList = new ArrayList<>();
- }
- public int getId(){
- return this.id;
- }
- public String getName(){
- return this.name;
- }
- public void addFriend(Person person){
- this.friendList.add(person);
- }
- public void introducePerson() {
- System.out.printf("Hey, I am %s and I am %d yers old :)\n", this.name, this.age);
- }
- public void sharePhone() {
- System.out.printf("You can contact me at %s\n", this.phone);
- }
- public void showFriends() {
- System.out.print("My friends are: ");
- for (int f = 0; f < friendList.size(); f++) {
- Person currentPerson = friendList.get(f);
- System.out.printf("%s ", currentPerson.getName());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement