Question: Java Already did number 1 and 2, I need help with numbers 3 and 4 - here's my code: IntegerList.java // **************************************************************** // IntegerList.java //
Java

Already did number 1 and 2, I need help with numbers 3 and 4 - here's my code:
IntegerList.java
// **************************************************************** // IntegerList.java // // Define an IntegerList class with methods to create & fill // a list of integers. // // ****************************************************************
public class IntegerList { int[] list; //values in the list int totalItems = 0;
//------------------------------------------------------- //create a list of the given size //------------------------------------------------------- public IntegerList(int size) { list = new int[size]; totalItems = list.length; }
//------------------------------------------------------- //fill array with integers between 1 and 100, inclusive //------------------------------------------------------- public void randomize() { for (int i=0; i // --------------------------------------------------------- // Increases the capacity of the integer list double // --------------------------------------------------------- private void increaseSize() { int temp[] = new int[list.length * 2]; System.arraycopy(list, 0, temp, 0, list.length); list = temp; } // ------------------------------------------------------- // Adds an integer value to the list // ------------------------------------------------------- public void addElement(int newVal) { totalItems++; if(list.length IntegerListTest.java //**************************************************************** //IntegerListTest.java // //Provide a menu-driven tester for the IntegerList class. // //**************************************************************** import java.util.Scanner; public class IntegerListTest { static IntegerList list = new IntegerList(10); static Scanner scan = new Scanner(System.in); //------------------------------------------------------- // Create a list, then repeatedly print the menu and do what the // user asks until they quit //------------------------------------------------------- public static void main(String[] args) { printMenu(); int choice = scan.nextInt(); while (choice != 0) { dispatch(choice); printMenu(); choice = scan.nextInt(); } } //-------------------------------------- // Do what the menu item calls for //-------------------------------------- public static void dispatch(int choice) { int loc; switch(choice) { case 0: System.out.println("Bye!"); break; case 1: System.out.println("How big should the list be?"); int size = scan.nextInt(); list = new IntegerList(size); list.randomize(); break; case 2: list.print(); break; case 3: System.out.println("Enter the number"); int newVal = scan.nextInt(); list.addElement(newVal); break; default: System.out.println("Sorry, invalid choice"); } } //---------------------------- // Print the user's choices //---------------------------- public static void printMenu() { System.out.println(" Menu "); System.out.println(" ===="); System.out.println("0: Quit"); System.out.println("1: Create a new list (** do this first!! **)"); System.out.println("2: Print the list"); System.out.println("3: Add Integer to the list"); System.out.print(" Enter your choice: "); } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
