/** A simple program to test a class Professor*/public class

/*
* A simple program to test a class Professor
*/
public class QO3
{
public static void main(String[] args) {

Professor rachel = new Professor(“Rachel”);
Professor joey = new Professor(“Joey”);
Professor ross = new Professor(“Ross”);
Professor monica = new Professor(“Monica”);
Professor chandler = new Professor(“Chandler”);
Professor phoebe = new Professor(“Phoebe”);

rachel.addCollaborator(joey);
rachel.addCollaborator(ross);
rachel.addCollaborator(monica);
rachel.addCollaborator(chandler);
rachel.addCollaborator(phoebe);

joey.addCollaborator(rachel);
joey.addCollaborator(ross);
joey.addCollaborator(monica);
joey.addCollaborator(chandler);
joey.addCollaborator(phoebe);

System.out.println(rachel.collaboratorsInCommon(joey));
System.out.println(joey.collaboratorsInCommon(rachel));

rachel.delCollaborator(monica);
System.out.println(rachel.collaboratorsInCommon(joey));
rachel.delCollaborator(chandler);
System.out.println(rachel.collaboratorsInCommon(joey));
rachel.delCollaborator(phoebe);
System.out.println(rachel.collaboratorsInCommon(joey));
rachel.delCollaborator(ross);
System.out.println(rachel.collaboratorsInCommon(joey));
System.out.println(“Expected:nRoss Monica Chandler PhoebenRoss Monica Chandler PhoebenRoss Chandler PhoebenRoss PhoebenRoss”);

}
}

Next file:

import java.util.ArrayList;
/*
* A Professor has a name and a list of Professors with whom they collaborate on research projects
*/
public class Professor
{
private String name;
private ArrayList collaborators;

/**
* Initializes name and collaborators variables
*/
public Professor(String nm)
{
  //———–Start below here. To do: approximate lines of code = 2
  // initialize instance variable name to nm, initialize collaborators to an empty array list
 
 
  //—————–End here. Please do not remove this comment. Reminder: no changes outside the todo regions.
}

/** Retrieves the name of the proferssor
* @return a string containing the professor’s name
*/
public String getName()
{
return name;
}

/** Adds a professor to the list of collaborators of this professor
* @param collaborator the professor to be added
*/
public void addCollaborator(Professor collaborator)
{
//———–Start below here. To do: approximate lines of code = 1
// add Professor collaborator to the collaborators array list

//—————–End here. Please do not remove this comment. Reminder: no changes outside the todo regions.
}

/** Removes a professor from the list of collaborators of this person.
* @param collaborator the Professor to be removed
*/
public void delCollaborator(Professor p)
{
//———–Start below here. To do: approximate lines of code = 1
// removes the professor p from the collaborators list.

//—————–End here. Please do not remove this comment. Reminder: no changes outside the todo regions.
}

/**
* Returns the array list of Professors representing the collaborators
*
*/
public ArrayList getCollaborators()
{
return collaborators;
}
/*
* Searches the collaborators list of this professor and the other professor’s list
* to see if they have collaborators in common.  
* @return a string containing the names of common collaborators where the names are separated by a ” “
* Ensure there is no space character after the last collaborator name
* return the empty string “” if there are no collaborators in common
*/
public String collaboratorsInCommon(Professor other)
{
//———–Start below here. To do: approximate lines of code = 10
// Hint: professors in common should not contain this professor name or other professor name

//Hint: remove any space characters at the end of the string. Make sure the string is not “” before removing spaces

//—————–End here. Please do not remove this comment. Reminder: no changes outside the todo regions.
}

}

 

Leave a Comment

Your email address will not be published. Required fields are marked *

GradeEssays.com
We are GradeEssays.com, the best college essay writing service. We offer educational and research assistance to assist our customers in managing their academic work. At GradeEssays.com, we promise quality and 100% original essays written from scratch.
Contact Us

Enjoy 24/7 customer support for any queries or concerns you have.

Phone: +1 213 3772458

Email: support@gradeessays.com

© 2024 - GradeEssays.com. All rights reserved.

WE HAVE A GIFT FOR YOU!

15% OFF 🎁

Get 15% OFF on your order with us

Scroll to Top