The objective of this project is to help you understand passing objects as parameters.
/** * Class Customer represents a cell phone customer * Each Customer has three friends which can be called * at a discounted rate. */ public class Customer { private String name; private String phoneNumber; Customer friend1; Customer friend2; Customer friend3; /** * Construct a Customer */ public Customer(String n, String phone) { name = n; phoneNumber = phone; Customer friend1 = null; Customer friend2 = null; Customer friend3 = null; } /** <<< COMPLETE THE CODE >>> * Add a new friend to the list as follows. * 1) Check to make sure friend is not already on the list. * 2) If not already on the list the new friend gets added as * friend1, the previous friend1 becomes friend2, * and friend2 is moved down the list to friend3. */ public void addFriend(Customer fnd) { <<< code NOT complete >>> } /** <<< COMPLETE THE CODE >>> * Checks to see if two people are on each others friend lists. * returns boolean: true or false */ public boolean isMutualFriend(Customer fnd) { <<< code NOT complete >>> } /** <<< COMPLETE THE CODE >>> * Return information about the Customer: * name, phone number, and list of friends names */ public String toString() { <<< code NOT complete >>> } // <<< ADD OTHER METHODS AS NEEDED: getters and setters >>> }
/** * <<< THIS CODE IS COMPLETE >>> * Tester for Customer class * * This tester should print out the following * * Name: Joe Mayo, Phone Number: 845-555-8723 * Friend1: Jack Klompus * Friend2: Sally Weaver * Friend3: Jake Jarmel * * Name: Jake Jarmel, Phone Number: 845-555-4663 * Friend1: SueEllen Mischke * Friend2: Sally Weaver * Friend3: Joe Mayo * * Name: Sally Weaver, Phone Number: 845-555-1323 * Friend1: David Puddy * Friend2: SueEllen Mischke * Friend3: Jack Klompus * * Joe Mayo and Jake Jarmel are mutual friends >>>true * * Joe Mayo and Sally Weaver are mutual friends >>>false * * Jake Jarmel and Sally Weaver are mutual friends >>>false * * Name: Sally Weaver, Phone Number: 845-555-1323 * Friend1: Joe Mayo * Friend2: David Puddy * Friend3: SueEllen Mischke * * Joe Mayo and Sally Weaver are mutual friends >>>true */ public class CustomerTester { public static void main(String[] args) { /** * add Customers to the list. */ Customer c1 = new Customer("Joe Mayo", "845-555-8723"); Customer c2 = new Customer("Jake Jarmel", "845-555-4663"); Customer c3 = new Customer("Sally Weaver", "845-555-1323"); Customer c4 = new Customer("Jack Klompus", "845-555-5417"); Customer c5 = new Customer("SueEllen Mischke", "845-555-9987"); Customer c6 = new Customer("David Puddy", "845-555-5473"); /** * add friends to Customer c1 */ c1.addFriend(c2); c1.addFriend(c3); c1.addFriend(c4); /** * add friends to Customer c2 */ c2.addFriend(c1); c2.addFriend(c3); c2.addFriend(c5); /** * add friends to Customer c3 */ c3.addFriend(c4); c3.addFriend(c5); c3.addFriend(c6); /** * print out information about customers */ System.out.println(c1); System.out.println(c2); System.out.println(c3); System.out.println("\n" + c1.getName() + " and " + c2.getName() + " are mutual friends >>>" + c1.isMutualFriend(c2)); System.out.println("\n" + c1.getName() + " and " + c3.getName() + " are mutual friends >>>" + c1.isMutualFriend(c3)); System.out.println("\n" + c2.getName() + " and " + c3.getName() + " are mutual friends >>>" + c2.isMutualFriend(c3)); c3.addFriend(c1); // add new friend to Customer c3 System.out.println(c3); System.out.println("\n" + c1.getName() + " and " + c3.getName() + " are mutual friends >>>" + c1.isMutualFriend(c3)); } }