Question: Complete the below code import java.util.*; /** * Requirements: * 1. Replace LastName in file and class names with your own name. * 2. Finish

Complete the below code import java.util.*;

/** * Requirements: * 1. Replace LastName in file and class names with your own name. * 2. Finish all TODOs. Test your code before submitting it. * 3. Do NOT modify ANY provided code. */ public class PROG24178_Assignment1_Lastname { public static void main(String[] args) { int pass = 0, total = 15; Person spiderman = new Person("Spiderman", 18); if (spiderman.getNumOfFriends() == 0 && !spiderman.removeFriend(null) && !spiderman.removeFriend("Spiderman") && spiderman.getAllFriendNames() == null) System.out.println("Pass #1: " + (++pass)); if (!spiderman.addFriend(null) && !spiderman.addFriend(new Person(null, 23))) System.out.println("Pass #2: " + (++pass)); if (spiderman.addFriend(new Person("MJ", 18)) && spiderman.addFriend(new Person("Ned", 18)) && spiderman.addFriend(new Person("Hulk", 27))) System.out.println("Pass #3: " + (++pass)); if (spiderman.getNumOfFriends() == 3 && spiderman.getAllFriendNames().length == 3) System.out.println("Pass #4: " + (++pass)); if (spiderman.getAllFriendNames()[0].equals("MJ") && spiderman.getAllFriendNames()[1].equals("Ned") && spiderman.getAllFriendNames()[2].equals("Hulk")) System.out.println("Pass #5: " + (++pass)); if (!spiderman.removeFriend("Thanos") && spiderman.removeFriend("Ned") && !spiderman.removeFriend("Ned")) System.out.println("Pass #6: " + (++pass)); if (spiderman.getNumOfFriends() == 2 && spiderman.getAllFriendNames().length == 2) System.out.println("Pass #7: " + (++pass)); if (!spiderman.addFriend(new Person("Hulk", 27))) System.out.println("Pass #8: " + (++pass)); if (spiderman.addFriend(new Person("Thor", 28)) && spiderman.addFriend(new Person("Ironman", 35)) && spiderman.addFriend(new Person("Dr. Strange", 32))) System.out.println("Pass #9: " + (++pass)); if (spiderman.getNumOfFriends() == 5 && spiderman.getAllFriendNames().length == 5) System.out.println("Pass #10: " + (++pass)); if (!spiderman.addFriend(new Person("Superman", 33))) System.out.println("Pass #11: " + (++pass)); if (spiderman.removeFriend("Thor") && spiderman.removeFriend("Ironman")) System.out.println("Pass #12: " + (++pass)); if (spiderman.getNumOfFriends() == 3 && spiderman.getAllFriendNames().length == 3) System.out.println("Pass #13: " + (++pass)); if (spiderman.removeFriend("Hulk") && spiderman.removeFriend("MJ") && !spiderman.removeFriend("Hulk")) System.out.println("Pass #14: " + (++pass)); if (spiderman.getNumOfFriends() == 1 && spiderman.getAllFriendNames().length == 1 && spiderman.getAllFriendNames()[0].equals("Dr. Strange")) System.out.println("Pass #15: " + (++pass)); System.out.println(" Pass/Total = " + pass + "/" + total); System.out.println(spiderman); } }

class Person { private static int numOfPerson; private String name; private int age; private int max private Person[] friends;

public Person(String name, int age) { this.name = name; this.age = age; friends = new Person[5]; //assume maximum 5 possible friends }

public String getName() { return name; }

public void setName(String name) { this.name = name; }

public int getAge() { return age; }

public void setAge(int age) { this.age = age; }

public Person[] getFriends() { return friends; }

@Override public String toString() { return "Person{" + "name='" + name + '\'' + ", age=" + age + ", friends=" + Arrays.toString(friends) + '}'; }

/* ==== Do NOT modify any code above this line ==== */

/** * TODO #1 - write a public method named getNumOfFriends that * - accepts no argument * - return the number of friends of this person (can be 0-5) */

/** * TODO #2 - write a public method named addFriend that * - accepts a person as the argument * - adds this person to the friends array * - returns true if the person is added successfully, otherwise returns false * - Note: a person can be added as a friend only when it is a valid person with a valid name * - Note: return false if the person is already a friend or the friend array is full */

End of Person class

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!