Question: Create the public class Module3 which does the following: 1) Holds a String array, initialized to size zero. 2) Using an infinite loop (eg.
Create the public class Module3 which does the following: 1) Holds a String array, initialized to size zero. 2) Using an infinite loop (eg. while(true)), prompts the user to enter commands via the console 3) Accepts three different user commands via the console with formats: list: For each array element, the application will sequentially list its index and String text, with each (index, String) pair separated by a space and printed on separate lines. 1. If the array is size zero, the message "no data found" will be printed 2. Any zero-length Strings will be displayed (as no text) with their index numbers . . . format example: User enters the command "list" output example: If the array contains the three Strings "first", "second", and "", the output should be "O first" on one line and "1 second" on the next and "2" on the last line. update [index] [String]: Changes the String text at the specified index to the specified String text, then gives a confirmation message with the old and new Strings and the index. format example: User enters the command "update 1 blue. output example: Suppose the existing text at index 1 is "second". An appropriate confirmation message would be something like "updated index 1 from second to blue". resize [size]: Rebuilds the String array as a new array with the specified size and copies all existing array elements into any valid indexes in the new array, assigns empty Strings to the others, then prints a confirmation message. Additional Constraints The String array should be an ordinary array, not one of the other Java Collection classes. There will be a substantial penalty for not using an ordinary array. Comments should be provided at the start of the file (.e.. above the class definition) giving the class author's name and the date the program was finished. Beyond that, you may choose how to approach the assignment. Any approach that processes console commands properly is acceptable. For example, you will probably use a Scanner object to receive user input but the instructions do not specify any particular way to use it. No exception handling is required - you may assume that the application user will only enter valid commands. format example: User enters the command "resize 5" action example 1: Suppose the array's size is 3. Then the indexes 0 through 2 will be copied into the new array and indexes 3 and 4 will created as zero-length Strings action example 2: Suppose the array's size is 8. Then the indexes 0 through 4 will be copied into the new array. Indexes 5 through 7 will be discarded. output example: After copying any array data, prints "array resized to size 5.
Step by Step Solution
3.41 Rating (148 Votes )
There are 3 Steps involved in it
Below is a simple implementation of the Module3 class in Java import javautilScanner Author Your Name Date February 2 2024 Description This class impl... View full answer
Get step-by-step solutions from verified subject matter experts
