Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

java programming!!!!!! (array)!!!! import java.util.Scanner; public class Assignment{ //------------------------------------------------------- // Create a list, then repeatedly print the menu and do what the // user asks

java programming!!!!!! (array)!!!!  import java.util.Scanner; public class Assignment{ //------------------------------------------------------- // Create a list, then repeatedly print the menu and do what the // user asks until they quit //------------------------------------------------------- public static void main(String[] args) { CharList list = null; char newChar, oldChar; Scanner scan = new Scanner (System.in); printMenu(); // ask a user to choose a command System.out.print(" Please enter a command or type? "); String choice = scan.next().toLowerCase(); char command = choice.charAt(0); while (command != 'q') { switch(command) { case 'a':// This option calls the constructor and initilaizes the array with random characters // it needs to be called first System.out.print(" Enter an integer for the array size? "); int size = scan.nextInt(); list = new CharList(size); list.randomize(); break; case 'b'://this option prints the list of chracters System.out.println(list.toString()); break; case 'c': //adds a new character to the list System.out.print(" Enter the new character to add to the list: "); newChar = scan.next().charAt(0); System.out.print(" Enter the index where you want to add the new character: "); int index = scan.nextInt(); list.addChar(newChar, index); break; case 'd'://remove the character from the list System.out.print(" Enter the character to delete: "); oldChar = scan.next().charAt(0); list.removeFirst(oldChar); break; case 'e'://prints the count of the letters in the list int[] temp = list.countLetters(); for (int i=0; i 

image text in transcribed

Sample Output: User input is in RED. Because characters are generated randomly, the characters in your array will look different from the sample output. Please check your result according to the operations of methods but not match the sample output directly. Menu --------------- a: Create a new list (** do this first!! **) b: Print the list of characters c: Add a character to the list d: Remove a character from the list e: Count the number of letters in the list q: Quit Please enter a command or type? a Enter an integer for the array size? 10 Please enter a command or type? b b m b u d o k o s m Please enter a command or type? c Enter the new character to add to the list: i Enter the index where you want to add the new character: 0 Please enter a command or type? c Enter the new character to add to the list: t Enter the index where you want to add the new character: 1 Please enter a command or type? d Enter the character to delete: b Please enter a command or type? b i t m b u d o k o s m Please enter a command or type? d Enter the character to delete: t Please enter a command or type? b i m b u d o k o s m Please enter a command or type? e a 0 b 1 c 0 d 1 e 0 f 0 g 0 h 0 i 1 j 0 k 1 l 0 m 2 n 0 o 2 p 0 q 0 r 0 s 1 t 0 u 1 v 0 w 0 x 0 y 0 z 0 Please enter a command or type? q Press any key to continue . . .

Part 2: Programming (13 points) Your assignment is to create a class called CharList in a file called CharList.java. (there is no main method in this class). The class CharList has two instance variables, an array of characters and an integer variable, which keeps track of the number of characters in the array Note: the number of elements is different from the size of the array The class CharList must include the following constructor and methods. (If your class does not contain any of the following methods, points will be deducted.) Method Description of the Method The constructor instantiates an array of characters using the given size Fills array with random characters between 'a" to z Adds a character (newChar) to the arry at the specified index and shifts all the elements (after passed index) to the right by one index. If the array is full, its size will be doubled first This method is private and it doubles the size of the arra Removes the first occurrence of newChar from the public CharList (int size) ublic void randomize () public void addChar (char newChar, int index) private void increasesize () public void removeFirst (int newChar)array and shifts all the elements (after the removed one) to the left by one index. this method returns an array of twenty-six int values, each of which stores the number of occurrence of each letter contained in the "charList". For example, the first element in the Displays the array of characters. You should print 10 characters per line public int[) countLetters) stores the number of occurrences for letter 'a public String toString ) wing program stored in Assignment7.iava Save the CharList class in a file called CharList.java and use the follo which has the main method to test your class. The main function prints the menu: Menu a: Create a new list (*do this first!!) b: Print the list of characters c: Add a character to the list at specified index d: Remove a character from the list e: Count the number of letters in the list q. Quit Here is the description for each opti on: a: Creates a new list with specific size from the user and fill the list with random cahracters between a' to 'z' b: It prints the characters using the toString method c: Adds a new character to the list by asking the user for the character and the index where the character will be added d: It deletes the first occurrence of the character entered by the user e: It counts the number of occurrence of each letter 'a, to z' in the array gquit

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

Big Data Systems A 360-degree Approach

Authors: Jawwad ShamsiMuhammad Khojaye

1st Edition

0429531575, 9780429531576

More Books

Students also viewed these Databases questions

Question

=+j Understand different types of regions in the world.

Answered: 1 week ago