Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program to display the following menu: 1) Enter string 2) String length

ID: 3602494 • Letter: W

Question

Write a program to display the following menu: 1) Enter string 2) String length 3) Count characters case sensitive 4) Count characters non case sensitive 5) Exit. The program should determine if option 1 was entered, before the user selects any of the other options (2-4). If user select a number from 2-4, a function should be called. All these functions should receive at least one parameter. Option 3 and 4 must return an integer value (representing the number of different characters in the c-string), and display a table as shown below. Option 5 will finish the program The string cannot be hard coded. A menu should be displayed (failing to display the menu will translate to 0 as homework grade) Given a string char str [ ] (1e. str [ ]- "Programming Assignment") A) (10 points) Write a recursive function to find the length of the string (option 2) B) (40 points) Write a recursive function that returns how many different (not including repeated entries) characters (case sensitive) are in the string (i.e, "T" is not the same as 't') Using this function display a table to indicate the number of different characters, and the number of times each character appears in the string, for example

Explanation / Answer

import java.util.*;

class Dynamic

{
ArrayList<Integer> arr;   

  
HashMap<Integer, Integer> hash;

public MyDS()
{
arr = new ArrayList<Integer>();
hash = new HashMap<Integer, Integer>();
}

void add(int x)
{
  
if (hash.get(x) != null)
return;

int s = arr.size();
arr.add(x);

hash.put(x, s);
}


void remove(int x)
{
Integer index = hash.get(x);
if (index == null)
return;

hash.remove(x);

int size = arr.size();
Integer last = arr.get(size-1);
Collections.swap(arr, index, size-1);

arr.remove(size-1);

hash.put(last, index);
}

int getRandom()
{
Random rand = new Random();
int index = rand.nextInt(arr.size());

return arr.get(index);
}

Integer search(int x)
{
return hash.get(x);
}
}

class Main
{
public static void main (String[] args)
{
Dynamic ds = new Dynamic();
ds.add(10);
ds.add(20);
ds.add(30);
ds.add(40);
System.out.println(ds.search(30));
ds.remove(20);
ds.add(50);
System.out.println(ds.search(50));
System.out.println(ds.getRandom());
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote