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

Project: List management Goal: creating, updating and displaying a list using a

ID: 3851629 • Letter: P

Question

Project: List management Goal: creating, updating and displaying a list using a menu. Instruction: Create an array called myList. Write a function called FirstElements for adding 100 random integers between 100 to 1000 to myList. Initialize the first 100 elements of myList by calling the FirstElements function. Create a menu to display the following options and a number corresponding to each option which is used for selecting the desired option: 1- adding any amount of numbers to myList 2- removing all occurrences of a selected number from myList 3- finding and displaying the maximum, minimum and range (maximum-minimum) in myList 4- finding the number of occurrences of a number in myList 5- doubling (multiplying by 2) all numbers in myList 6- display all members of myList. 7- quit for each menu item create a function. when the item number is typed, the function should be executed, the required inputs should be requested, and the proper output should be produced. the outputs can be formatted in a proper fashion of your choice after executing any function in the menu, the user should be given the choice to select another menu or quit (Y for the new request and Q for quit). if the user has a new request, the menu should appear again and the process repeated.

Explanation / Answer

Hi, fully working code. added comments for you to understand.

import java.util.*;
import java.lang.*;
import java.io.*;
import java.util.concurrent.ThreadLocalRandom;


class Codechef
{
   static Scanner reader = new Scanner(System.in);//for reading input
   public static void main (String[] args) throws java.lang.Exception
   {
  
      
       List<Integer> myList= new ArrayList<Integer>();// our list
       myList=firstElements(); // initializing
       char c='y';
       while(c!='q')// while user doesnt press quit
       {
           System.out.println("please choose the desired option");
       System.out.println("1.adding any amount of numbers to myList");
       System.out.println("2.removing all occurences of a selected number from myList");
       System.out.println("3.finding and displaying min,max and range ");
       System.out.println("4.finding the number of occurence of a number in myList");
       System.out.println("5.doubling all numbers in myList");
       System.out.println("6.display all members of myList");
       System.out.println("7.quit");
           int n = reader.nextInt();
           switch(n) { // switch over menu number chosen
case 1 :
add(myList);
break;
case 2 :
    remove(myList);
    break;
   
case 3 :
range(myList);
break;
case 4 :
    find(myList);
    break;

case 5 :
multiply(myList);
break;
case 6 :
print(myList);
break;
  
case 7 :
return;
  
}
           System.out.println("do you want to continue? press y or q");
           c = reader.next().charAt(0);
       }

      
   }
public static   List<Integer> firstElements()// initializes with random numbers between 100 and 1000
{
int randomNum;
       List<Integer> a= new ArrayList<Integer>();
for(int i=0;i<100;i++)// 100 elements
{
randomNum= ThreadLocalRandom.current().nextInt(100, 1000 + 1);// gets random no between 100 and 1000
a.add(randomNum);
}
return a;

}
public static   void add(List<Integer> a)// add elements
{
        System.out.println("enter the number of entries to be added");
   
        int n = reader.nextInt();
               System.out.println("enter the entries to be added");
        for(int i=0;i<n;i++)
        {
       a.add(reader.nextInt());           
        }

}
public static   void remove(List<Integer> a)// remove element
{
   System.out.println("enter the entry to be removed");
       
        int n = reader.nextInt();
a.removeAll(Collections.singleton(n));


}
public static   void range(List<Integer> a)//print range
{
   System.out.println("max "+Collections.max(a));
   System.out.println("min "+Collections.min(a));
   System.out.println("range "+(Collections.max(a)-Collections.min(a)));


}
public static   void multiply(List<Integer> a)// double all elements
{
   for(int i=0;i<a.size();i++)
   {
       a.set(i,a.get(i)*2);
   }

}
public static   void print(List<Integer> a)//display list
{
       System.out.println(a);
}

public static void find(List<Integer> a)// search for an element
{
   System.out.println("enter the entry to be searched");
   
        int n = reader.nextInt();
       
       System.out.println(Collections.frequency(a,n));
}
  


}

Thumbs up if this was helpful. otherwise let me know in comments.