Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You are required to write an interactive Java program that prompts the user for commands, accepts commands from the keyboard (stdin), and executes those commands.

You are required to write an interactive Java program that prompts the user for commands, accepts commands from the keyboard (stdin), and executes those commands. When a command requires output, it must be written to stdout. The program must continue to process commands until the user types the end command. The program deals with linked lists. Each node of the list will contain a string, a positive integer, i.e. an integer value n 1, and a pointer to the next node of the list. For any node, the string and integer stored in that node will be referred to as the symbol and count respectively. At all times, the list must satisfy the following two important properties: 1. The symbols appearing in the list shall be all distinct. 2. When the list is scanned from left to right, the counts must be in non-increasing order. Initially, the list is empty. Some commands require your program to modify the list while others involve traversing the list to gather and print information about the list. The commands and their interpretations are as follows: 1. Insert Command: The syntax for this command is as follows: ins str where str represents a string. The interpretation of the command is as follows: (a) If the list contains a node whose symbol is identical to str, then the count stored at that node must be incremented by 1. After this increment, if necessary, the node must be moved to the appropriate position in the list to ensure that the counts are in non-increasing order. (b) If the list does not contain a symbol identical to str, then a new node is created. The symbol stored in the new node is the string specified by the command and the count stored in the new node must be 1. The new node must be inserted at the end of the list. Note: The ins command does not produce any output. 2. Delete Command: The syntax for this command is defined as follows: del str Here, del represents the name of the command and str represents a string. The interpretation of the command is as follows: (a) If the list contains a node whose symbol is identical to str, then the count stored in that node must be decreased by 1. If the new count becomes 0, then the node must be removed from the list. If the new count is at least 1, then the node must be moved, if necessary, to an appropriate position in the list to ensure that the counts are in non-increasing order. (b) If the list does not contain a node whose symbol is identical str, then your program must leave the list unchanged.3. Print Statistics Command: The syntax for the command is as follows: pst Here pst represents the name of the command. If the list is empty, then your program should simply print the message the list is empty.. Otherwise, (i.e. the list is non-empty), your program must compute and print the following quantities: (a) The number of nodes in the list; (b) The maximum count in the list; (c) The minimum count of the list; (d) The average count of the list. (Bear in mind, that the average of the counts is a real number in general). 4. Print List Command: The syntax for the command is as follows: prl Here, prl represents the name of the command. If the list is empty, your program should print the message the list is empty.. Otherwise your program should traverse the list (from left to right) and print each symbol and the corresponding count on a line by itself. (This, if the list is non-empty, the number of lines printed is the number of nodes in the list). 5. End Command: The syntax for the command is as follows: end In response to this command, your program must stop. 2 Structural Requirements 1. Your program should implement each of the above commands in a separate method. (You may also include other methods than these as needed). 2. Your program must use at least three classes. The description of these classes is as follows: (a) You must have a class to handle parsing the commands from the user. This class must have a main method and will be the entry point of your program. (b) You must have a class to implement and maintain the linked list. It is in this class where all of your methods for implementing the commands should be placed. (c) You must have a class to implement the nodes of the linked list. Remember, this class will need the appropriate accessors and mutators along with the required fields for the symbol and count.

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

OCA Oracle Database SQL Exam Guide Exam 1Z0-071

Authors: Steve O'Hearn

1st Edition

1259585492, 978-1259585494

More Books

Students also viewed these Databases questions

Question

Discuss the long-term prospects for tourism.

Answered: 1 week ago

Question

=+a) Show that mixing implies ergodicity.

Answered: 1 week ago

Question

=+what you can edit out yet still get the message across.

Answered: 1 week ago

Question

=+3. How could you extend the campaign creatively?

Answered: 1 week ago