Suppose a large corporation wishes to hold meetings with a committee of executives consisting of both its own executives as well as executives from other companies. This corporation needs a program to maintain a list of executives who will be present at a given meeting. The program should also keep track of where these executives will be seated in relation to one another at one of these meetings, given that the meeting will take place in the corporation's conference room around a large, circular table as shown below:
Your task for this assignment is to write a program that makes use of a circular doubly-linked list and provides a menu of options for performing operations on the current seating plan.
1. Write a fully-documented class named Executive that is used to represent information about an Executive who will be attending a meeting.
This class should keep track of the full name of the Executive and the name of the corporation he or she works for, both of which are to be stored as Strings. You should provide for this class a constructor as well as any necessary accessor/mutator methods.
2. Write a fully-documented class named ExecutiveNode that contains a reference to an Executive object as well as to two other ExecutiveNode objects, referred to as left and right. Below is a partial specification and it is up to you to fill in the remaining details:
public class ExecutiveNode
Constructor for ExecutiveNode
public ExecutiveNode()
setExecutive
public void setExecutive(Executive exec)
getExecutive
public Executive getExecutive()
setRight
public void setRight(ExecutiveNode node)
setLeft
public void setLeft(ExecutiveNode node)
getRight
public ExecutiveNode getRight()
getLeft
public ExecutiveNode getLeft()
3. Write a fully-documented class named ExecutiveList which represents a circular doubly-linked list. The first Executive that will be contained in this list (i.e., the one passed as a parameter to the ExecutiveList constructor), will be considered to be the chairperson of the meeting. The ExecutiveList class will therefore contain a pointer named chair to the node containing this particular executive. It is worth noting that the chairperson cannot be removed from this list and at no time can the chairperson be changed to a different executive. Your class will follow this specification, but you have to fill in the details:
public class ExecutiveList
Constructor for ExecutiveList
public ExecutiveList(Executive chairperson)
Constructs a new ExecutiveList with the given Executive object as the chairperson for the meeting. The list should contain a single node, chair, containing the given Executive and, by default, the person to the left and the person to the right of the chairperson should be the chairperson Executive object itself.
insertLeftOfChair
public void insertLeftOfChair(Executive exec)
Places the given Executive to the left of the chairperson in the meeting. The executive who was previously sitting to the left of the chairperson is now to the left of the given Executive, and the chairperson is now to the right of the given Executive.
insertRightOfExec
public boolean insertRightOfExec(Executive exec, String target)
Places the given Executive to the right of an executive already in the list with the name target.
If there are multiple executives in the list with the name target, insert the new Executive to the right of the first Executive reached with the name target by following right links beginning with the chairperson.
If no executive in list has the name target, return false without inserting the new Executive.
Otherwise, the return value is true.
insertLeftOfExec
public boolean insertLeftOfExec(Executive exec, String target)
Places the given Executive to the left of an executive already in the list with the name target.
If there are multiple executives in the list with the name target, insert the new Executive to the left of the first Executive reached with the name target by following right links beginning with the chairperson.
If no executive in list has the name target, return false without inserting the new Executive.
Otherwise, the return value is true.
removeTargetExec
public boolean removeTargetExec(String name)
Removes an executive with the given name from the list.
If there are multiple executives in the list with the given name, remove the first Executive reached with the name target by following right links beginning with the chairperson.
If the chairperson is the only executive with the given name, return false without removing any executives.
If the chairperson shares the given name with other executives, remove the first executive other than the chairperson with the given name by following right links beginning with the chairperson.
If no executive is in the list with the given name, return false without removing any executives.
Otherwise, the return value is true.
NOTE: Do not destroy the list as you do this.
removeByCorporation
public int removeByCorporation(String corporation)
Removes all executives from the list that belong to a given corporation.
If the corporation is the name of the corporation that the chairperson belongs to, do not remove any executives and return a value of -1.
Otherwise, remove all executives belonging to the specified corporation.
The return value is equal to the number of executives removed in this process.
NOTE: Do not destroy the list as you do this.
printByCorporation
public void printByCorporation(String corporation)
Prints a list of the names of all executives belonging to the specified corporation. Each name should be printed on its own separate line.
The names should appear in counter-clockwise order (i.e., by following right links) beginning with the position of the chairperson.
printAllClockwise
public void printAllClockwise()
Prints a list of the names and corporations of all executives in the list in a clockwise direction.
For each executive, a comma and the name of his or her corporation should follow the name of the executive. Information about each executive (name and corporation) should appear on separate lines (one line per executive).
The names should appear in clockwise order (i.e., by following left links) beginning with the position of the chairperson.
printAllCounterClockwise
public void printAllCounterClockwise()
Prints a list of the names and corporations of all executives in the list in a counter-clockwise direction.
For each executive, a comma and the name of his or her corporation should follow the name of the executive. Information about each executive (name and corporation) should appear on separate lines (one line per executive).
The names should appear in counter-clockwise order (i.e., by following right links) beginning with the position of the chairperson.
4. Write a fully-documented class named MeetingManager. This class will contain a main method that first prompts the user for the name and corporation of a meeting's chairperson and then presents a menu that allows the user to perform the following operations on the seating arrangements for that meeting:
ILC (Insert an executive to the Left of the Chairperson)
Prompts the user for the name and corporation of an executive to be added to the meeting.
This executive is to be seated to the left of the meeting's chairperson.
ILE (Insert an executive to the Left of a given Executive)
Prompts the user for the name and corporation of an executive and the name of an executive already in the meeting.
If the executive already in the meeting is in fact in the list of executives, the new executive is seated to the left of that executive.
Otherwise, print an appropriate error message and do not insert the new executive.
IRE (Insert an executive to the Right of a given Executive)
Prompts the user for the name and corporation of an executive and the name of an executive already in the meeting.
If the executive already in the meeting is in fact in the list of executives, the new executive is seated to the right of that executive.
Otherwise, print an appropriate error message and do not insert the new executive.
RTE (Remove Target Executive)
Prompts the user for the name of an executive to be removed from the meeting.
If the name entered matches the name of the chairperson, remove an executive who shares that name with the chairperson, if one exists.
Otherwise, print an appropriate error message.
In all other cases, remove an executive whose name matches the target name, if such an executive exists, or print an appropriate error message.
RBC (Remove By Corporation)
Prompts the user for the name of a corporation.
If the name of the corporation entered matches the name of the chairperson's corporation, print an appropriate error message.
Otherwise, remove all executives belonging to the specified corporation and print a message indicating the number of executives removed from the meeting in this process.
PBC (Print By Corporation)
Prompts the user for the name of a corporation.
Prints the names of all executives who belong to the given corporation in counter-clockwise order starting at the position of the chairperson.
PCC (Print all in Counter-Clockwise order)
Prints the name and corporation for each executive at the meeting in counter-clockwise order beginning with the chairperson.
PCL (Print all in CLockwise order)
Prints the name and corporation for each executive at the meeting in clockwise order beginning with the chairperson.
EXT (EXiTs the program)
INPUT FORMAT
All names and menu options are case-insensitive. You should use the equalsIgnoreCase method of the String class for these comparisons.
INPUT FORMAT
All names and menu options are case-insensitive. You should use the equalsIgnoreCase method of the String class for these comparisons.
There are no restrictions on the content of the Strings input for corporation and/or executive names.
OUTPUT FORMAT
The user must be prompted each time that input is requested by the program.
For lists of executives, information about each executive should appear on separate lines.
All error messages should be informative and correctly explain to the user what the situation is.
SAMPLE INPUT/OUTPUT:
Note that computer output is in blue and comments are in green.
//This the opening prompt for the program:
Enter the name of the chairperson: Tom Jones
Enter the corporation of the chairperson: ABC Inc.
Please select an option from the following menu:
ILC)Insert to Left of Chairperson
ILE)Insert to Left of Executive
IRE)Insert to Right of Executive
RTE)Remove Target Executive
RBC)Remove By Corporation
PBC)Print By Corporation
PCC)Print All Counter-Clockwise
PCL)Print All Clockwise
EXT)Exit Program
Please select an option: PCC
//Only prints the chairperson:
Tom Jones, ABC Inc.
Insertion successful.
Please select an option from the following menu:
ILC)Insert to Left of Chairperson
ILE)Insert to Left of Executive
IRE)Insert to Right of Executive
RTE)Remove Target Executive
RBC)Remove By Corporation
PBC)Print By Corporation
PCC)Print All Counter-Clockwise
PCL)Print All Clockwise
EXT)Exit Program
Please select an option: ILC
Enter the name of the executive: Ed Wilson
Enter the corporation of the executive: ABC Inc.
Insertion successful.
Please select an option from the following menu:
ILC)Insert to Left of Chairperson
ILE)Insert to Left of Executive
IRE)Insert to Right of Executive
RTE)Remove Target Executive
RBC)Remove By Corporation
PBC)Print By Corporation
PCC)Print All Counter-Clockwise
PCL)Print All Clockwise
EXT)Exit Program
Please select an option: PCC
//Print the List:
Tom Jones, ABC Inc.
Ed Wilson, ABC Inc.
Please select an option from the following menu:
ILC)Insert to Left of Chairperson
ILE)Insert to Left of Executive
IRE)Insert to Right of Executive
RTE)Remove Target Executive
RBC)Remove By Corporation
PBC)Print By Corporation
PCC)Print All Counter-Clockwise
PCL)Print All Clockwise
EXT)Exit Program
Please select an option: ILE
//Insert Mark Johnson to Ed Wilson's left and Tom Jones' right:
Enter the name of the new executive: Mark Johnson
Enter the corporation of the new executive: ABC Inc.
Enter the name of the target executive: Ed Wilson
Insertion successful.
Please select an option from the following menu:
ILC)Insert to Left of Chairperson
ILE)Insert to Left of Executive
IRE)Insert to Right of Executive
RTE)Remove Target Executive
RBC)Remove By Corporation
PBC)Print By Corporation
PCC)Print All Counter-Clockwise
PCL)Print All Clockwise
EXT)Exit Program
Please select an option: PCC
//Print the List:
Tom Jones, ABC Inc.
Mark Johnson, ABC Inc.
Ed Wilson, ABC Inc.
Please select an option from the following menu:
ILC)Insert to Left of Chairperson
ILE)Insert to Left of Executive
IRE)Insert to Right of Executive
RTE)Remove Target Executive
RBC)Remove By Corporation
PBC)Print By Corporation
PCC)Print All Counter-Clockwise
PCL)Print All Clockwise
EXT)Exit Program
Please select an option: IRE
//Insert Steve Paxson to Tom Jones' left and Ed Wilson's right:
Enter the name of the new executive: Steve Paxson
Enter the corporation of the new executive: Dell Computers
Enter the name of the target executive: Ed Wilson
Insertion successful.
Please select an option from the following menu:
ILC)Insert to Left of Chairperson
ILE)Insert to Left of Executive
IRE)Insert to Right of Executive
RTE)Remove Target Executive
RBC)Remove By Corporation
PBC)Print By Corporation
PCC)Print All Counter-Clockwise
PCL)Print All Clockwise
EXT)Exit Program
Please select an option: PCC
//Print the List:
Tom Jones, ABC Inc.
Mark Johnson, ABC Inc.
Ed Wilson, ABC Inc.
Steve Paxson, Dell Computers
Please select an option from the following menu:
ILC)Insert to Left of Chairperson
ILE)Insert to Left of Executive
IRE)Insert to Right of Executive
RTE)Remove Target Executive
RBC)Remove By Corporation
PBC)Print By Corporation
PCC)Print All Counter-Clockwise
PCL)Print All Clockwise
EXT)Exit Program
Please select an option: IRE
//Insert another Mark Johnson to Ed Wilson's left and the original Mark Johnson's right:
Enter the name of the new executive: Mark Johnson
Enter the corporation of the new executive: Dell Computers
Enter the name of the target executive: Mark Johnson
Insertion successful.
Please select an option from the following menu:
ILC)Insert to Left of Chairperson
ILE)Insert to Left of Executive
IRE)Insert to Right of Executive
RTE)Remove Target Executive
RBC)Remove By Corporation
PBC)Print By Corporation
PCC)Print All Counter-Clockwise
PCL)Print All Clockwise
EXT)Exit Program
Please select an option: PCC
//Print the List:
Tom Jones, ABC Inc.
Mark Johnson, ABC Inc.
Mark Johnson, Dell Computers
Ed Wilson, ABC Inc.
Steve Paxson, Dell Computers
Please select an option from the following menu:
ILC)Insert to Left of Chairperson
ILE)Insert to Left of Executive
IRE)Insert to Right of Executive
RTE)Remove Target Executive
RBC)Remove By Corporation
PBC)Print By Corporation
PCC)Print All Counter-Clockwise
PCL)Print All Clockwise
EXT)Exit Program
Please select an option: PCL
//Print the List in the other direction:
Tom Jones, ABC Inc.
Steve Paxson, Dell Computers
Ed Wilson, ABC Inc.
Mark Johnson, Dell Computers
Mark Johnson, ABC Inc.
Please select an option from the following menu:
ILC)Insert to Left of Chairperson
ILE)Insert to Left of Executive
IRE)Insert to Right of Executive
RTE)Remove Target Executive
RBC)Remove By Corporation
PBC)Print By Corporation
PCC)Print All Counter-Clockwise
PCL)Print All Clockwise
EXT)Exit Program
Please select an option: RTE
//Removes Mark Johnson of ABC Inc. (he is the first one reached by right links):
Enter the name of the executive to remove: Mark Johnson
The executive has been removed from meeting.
Please select an option from the following menu:
ILC)Insert to Left of Chairperson
ILE)Insert to Left of Executive
IRE)Insert to Right of Executive
RTE)Remove Target Executive
RBC)Remove By Corporation
PBC)Print By Corporation
PCC)Print All Counter-Clockwise
PCL)Print All Clockwise
EXT)Exit Program
Please select an option: PCC
//Print the List:
Tom Jones, ABC Inc.
Mark Johnson, Dell Computers
Ed Wilson, ABC Inc.
Steve Paxson, Dell Computers
Please select an option from the following menu:
ILC)Insert to Left of Chairperson
ILE)Insert to Left of Executive
IRE)Insert to Right of Executive
RTE)Remove Target Executive
RBC)Remove By Corporation
PBC)Print By Corporation
PCC)Print All Counter-Clockwise
PCL)Print All Clockwise
EXT)Exit Program
Please select an option: PBC
//List all executives from Dell Computers:
Enter the name of the corporation to display: Dell Computers
Mark Johnson, Dell Computers
Steve Paxson, Dell Computers
Please select an option from the following menu:
ILC)Insert to Left of Chairperson
ILE)Insert to Left of Executive
IRE)Insert to Right of Executive
RTE)Remove Target Executive
RBC)Remove By Corporation
PBC)Print By Corporation
PCC)Print All Counter-Clockwise
PCL)Print All Clockwise
EXT)Exit Program
Please select an option: RBC
//Try to remove all ABC Inc. executives (causes an error):
Enter the name of the corporation to remove: ABC Inc.
Invalid command: cannot remove all employees from the chairperson's corporation.
Please select an option from the following menu:
ILC)Insert to Left of Chairperson
ILE)Insert to Left of Executive
IRE)Insert to Right of Executive
RTE)Remove Target Executive
RBC)Remove By Corporation
PBC)Print By Corporation
PCC)Print All Counter-Clockwise
PCL)Print All Clockwise
EXT)Exit Program
Please select an option: PCC
//Print the List:
Tom Jones, ABC Inc.
Mark Johnson, Dell Computers
Ed Wilson, ABC Inc.
Steve Paxson, Dell Computers
Please select an option from the following menu:
ILC)Insert to Left of Chairperson
ILE)Insert to Left of Executive
IRE)Insert to Right of Executive
RTE)Remove Target Executive
RBC)Remove By Corporation
PBC)Print By Corporation
PCC)Print All Counter-Clockwise
PCL)Print All Clockwise
EXT)Exit Program
Please select an option: RBC
//Try to remove all executives from a non-existent corporation:
Enter the name of the corporation to remove: New Corporation
0 executive(s) have been removed from the meeting.
Please select an option from the following menu:
ILC)Insert to Left of Chairperson
ILE)Insert to Left of Executive
IRE)Insert to Right of Executive
RTE)Remove Target Executive
RBC)Remove By Corporation
PBC)Print By Corporation
PCC)Print All Counter-Clockwise
PCL)Print All Clockwise
EXT)Exit Program
Please select an option: RBC
//Try to remove all executives from Dell Computers:
Enter the name of the corporation to remove: Dell Computers
2 executive(s) have been removed from the meeting.
Please select an option from the following menu:
ILC)Insert to Left of Chairperson
ILE)Insert to Left of Executive
IRE)Insert to Right of Executive
RTE)Remove Target Executive
RBC)Remove By Corporation
PBC)Print By Corporation
PCC)Print All Counter-Clockwise
PCL)Print All Clockwise
EXT)Exit Program
Please select an option: PCC
//Print the List:
Tom Jones, ABC Inc.
Ed Wilson, ABC Inc.
Please select an option from the following menu:
ILC)Insert to Left of Chairperson
ILE)Insert to Left of Executive
IRE)Insert to Right of Executive
RTE)Remove Target Executive
RBC)Remove By Corporation
PBC)Print By Corporation
PCC)Print All Counter-Clockwise
PCL)Print All Clockwise
EXT)Exit Program
Please select an option: IRE
//Attempt an invalid insertion:
Enter the name of the new executive: Mark Johnson
Enter the corporation of the new executive: Dell Computers
Enter the name of the target executive: Mark Johnson //Not currently in list
Invalid command: Executive not found in list.
Please select an option from the following menu:
ILC)Insert to Left of Chairperson
ILE)Insert to Left of Executive
IRE)Insert to Right of Executive
RTE)Remove Target Executive
RBC)Remove By Corporation
PBC)Print By Corporation
PCC)Print All Counter-Clockwise
PCL)Print All Clockwise
EXT)Exit Program
Please select an option: IRE
//Insert another Tom Jones:
Enter the name of the new executive: Tom Jones
Enter the corporation of the new executive: Dell Computers
Enter the name of the target executive: Tom Jones
Insertion successful.
Please select an option from the following menu:
ILC)Insert to Left of Chairperson
ILE)Insert to Left of Executive
IRE)Insert to Right of Executive
RTE)Remove Target Executive
RBC)Remove By Corporation
PBC)Print By Corporation
PCC)Print All Counter-Clockwise
PCL)Print All Clockwise
EXT)Exit Program
Please select an option: PCC
//Print the List:
Tom Jones, ABC Inc.
Tom Jones, Dell Computers
Ed Wilson, ABC Inc.
Please select an option from the following menu:
ILC)Insert to Left of Chairperson
ILE)Insert to Left of Executive
IRE)Insert to Right of Executive
RTE)Remove Target Executive
RBC)Remove By Corporation
PBC)Print By Corporation
PCC)Print All Counter-Clockwise
PCL)Print All Clockwise
EXT)Exit Program
Please select an option: RTE
//Removes Tom Jones of Dell Computers (the chairperson cannot be removed):
Enter the name of the executive to remove: Tom Jones
The executive has been removed from meeting.
Please select an option from the following menu:
ILC)Insert to Left of Chairperson
ILE)Insert to Left of Executive
IRE)Insert to Right of Executive
RTE)Remove Target Executive
RBC)Remove By Corporation
PBC)Print By Corporation
PCC)Print All Counter-Clockwise
PCL)Print All Clockwise
EXT)Exit Program
Please select an option: RTE
//Fails to remove Tom Jones (the chairperson cannot be removed):
Enter the name of the executive to remove: Tom Jones
Invalid command: The chairperson cannot be removed from the meeting.
Please select an option from the following menu:
ILC)Insert to Left of Chairperson
ILE)Insert to Left of Executive
IRE)Insert to Right of Executive
RTE)Remove Target Executive
RBC)Remove By Corporation
PBC)Print By Corporation
PCC)Print All Counter-Clockwise
PCL)Print All Clockwise
EXT)Exit Program
Please select an option: EXT
Program terminated normally...
이게 두번째 숙제였고 자바로 짜야함
물론 API 못 씀 ㅋㅋ 직접 링크드 리스트 만들고.
댓글 영역
획득법
① NFT 발행
작성한 게시물을 NFT로 발행하면 일주일 동안 사용할 수 있습니다. (최초 1회)
② NFT 구매
다른 이용자의 NFT를 구매하면 한 달 동안 사용할 수 있습니다. (구매 시마다 갱신)
사용법
디시콘에서지갑연결시 바로 사용 가능합니다.