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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started