Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Transport Operations

Authors: Allen Stuart

2nd Edition

978-0470115398, 0470115394

Students also viewed these Programming questions

Question

how to state the needs for a dnp project on th eproposal sheet

Answered: 1 week ago

Question

=+1 What is the business doing now? Where are we now?

Answered: 1 week ago