Question: Can someone show me how to code these two functions but in a different way from which they are already. I want these functions to
Can someone show me how to code these two functions but in a different way from which they are already. I want these functions to still be able to do what its doing. It should still be able to go through an arrayList of contacts and if the linkedlnUser equals the user already, throw an exception. If not then add the user.
The same thing but in a different way.
public void addConnection(LinkedInUser user) throws LinkedInException{
for(LinkedInUser linkedInUser : this.connections) {
if(linkedInUser.equals(user)) {
throw new LinkedInException("Error: Already Connected");
}
}
this.connections.add(user);
}
public void removeConnection(LinkedInUser user) throws LinkedInException {
for(LinkedInUser linkedInUser : this.connections) {
if(linkedInUser.equals(user)) {
this.connections.remove(user);
return;
}
}
throw new LinkedInException("Error: Not Connected");
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
