i am stuck on parts e and f exercise 1 numberlisttester java class numberlist implem 5196265

I am stuck on parts E and F

Exercise 1:      NumberListTester.java

Class NumberList implements a simple list of Integers, using an ArrayList. NumberListTester generates 10 random, positive, 2-digit ints, and adds them to the list. It then calls method printList which prints the items on the list.

Run the program until you understand what it does.

a. Write the body of the method printReversed, which prints the list items in reverse order. Add a statement in main to call printReversed after the call to printList.

Check ______

b. Write the body of the method printEveryOther, which prints every other item on the list, beginning with the first one.   In main, replace the statement that calls printReversed with one that calls printEveryOther.

Check ______

c. Write the body of the method printEvens, which prints all the even-numbered ints on the list.   In main, replace the statement that calls printEveryOther with one that calls printEvens.

Check ______

All this printing is getting a bit tedious. Let's try some more fun operations.

d.   0.   Add a new ArrayList-of-integer instance variable called bigList to the NumberList class

Add a statement to the NumberList constructor that creates an empty ArrayList object pointed to by bigList

Delete the call to printEvens from main.

Write the body of the method splitList, which copies all ints that are greater than or equal to 50 from aList to bigList.

Add a method to the NumberList class to print bigList.

Add a sequence of method calls in main to verify that the splitList method is working correctly. I.e., after calling splitList, call again the method that prints the original list and then call the method you wrote in step 4 to print the bigList.

Check _____

E. Add a method insert to the NumberList class that takes two parameters of type int. The first parameter is the index at which to insert a new number into the list, and the second is the number to be inserted.   E.g., if the first param is 4 and the second is 37, then 37 will be inserted at index 4 in aList (i.e., as the new 5th list element). The number inserted does not replace the number currently at that position, but is inserted just before it.

Hint: The ArrayList class has a method that does exactly this. Call that method from your insert method.

Now add statements to main to allow the user to specify the number to insert and the position at which to insert it. Then, after inserting the new number, print the updated list.

Check _____

F. Finally, add code to your insert method that will assure that an IndexOutOfBoundsException cannot be thrown. I.e., your insert method should just print an appropriate error message if the first parameter — the index at which to insert the new Integer — is illegal.

Hint: What are the legal indices for an ArrayList? What is the smallest? What is the largest? What about the special case of inserting a new value at the end of the list? Try it!

Check _____

MY CODE SO FAR:

import java.util.ArrayList ;
import java.util.Random ;

/**
* A class to provide practice using ArrayLists
*/
class NumberList
{
   // instance var's
   private ArrayList aList ;// a list of Integer objects
private ArrayList bigList;

   /**
   * Creates a NumberList object.
   */  
   public NumberList()
   {
       aList = new ArrayList() ;   // creates an empty list
bigList = new ArrayList();
   }
  
   /**
   * Adds a number to the list.
   * @param number the number to be added to the list
   */
   public void add(int number)
   {
       aList.add(number) ;       // calls add method of ArrayList class
   }
  
   /**
   * Prints the numbers stored in aList.
   */
   public void printList()
   {
       System.out.println( “The numbers on the list: ” ) ;
      
       // for each number on the list, from 1st to last…
       for (int i = 0 ; i
       {
           int number = aList.get(i) ;               // get the number
           System.out.print(number + ” “) ;       // print it
       }
       System.out.println(“n”) ;
   }
  
   /**
   * Prints the numbers stored in aList, in reverse order.
   */
   public void printReversed()
   {
       System.out.println( “The numbers on the list, in reverse order: ” ) ;
       for (int i = aList.size()-1 ; i >= 0 ; i–)
       {
           int number = aList.get(i) ;               // get the number
           System.out.print(number + ” “) ;       // print it
       }
       System.out.println(“n”) ;
      
      
   }
  
   /**
   * Prints every other number stored in aList, starting with the first one.
   */
   public void printEveryOther()
   {
       System.out.println( “Starting with the first, every other number: ” ) ;
       for (int i = 0 ; i
       {
           int number = aList.get(i) ;               // get the number
           System.out.print(number + ” “) ;       // print it
       }
       System.out.println(“n”) ;
      
      
   }

   /**
   * Prints all the even-numbered ints stored in aList.
   */
   public void printEvens()
   {
       System.out.println( “The even numbers on the list: ” ) ;
       for (int i = 0 ; i
       {
           if(aList.get(i) % 2 == 0){
int number = aList.get(i) ;               // get the number
           System.out.print(number + ” “) ;       // print it
       }
}
       System.out.println(“n”) ;
      
      
   }

   /**
   * Copies all ints that are 50 or greater from aList to bigList.
   */
   public void splitList()
   {
System.out.println( “The numbers on the big list, greater than 50: ” ) ;
       for (int i = 0 ; i
       {
if(aList.get(i) >= 50){
int c = aList.get(i);
bigList.add(c);               // get the number
           System.out.print(c + ” “) ;       // print it
       }
}
       System.out.println(“n”) ;
      
          
   }
  
  
  
}

public class NumberListTester
{
   public static void main (String [] args)
   {
       Random r = new Random() ;
       NumberList list = new NumberList() ;
      
       // populate the list with 10 random 2-digit ints (10 to 99)
       for (int i = 1 ; i
       {
           int next = r.nextInt(90) + 10 ;
           // call the “add” method of the NumberList class
           list.add( next ) ;              
       }

       // print the aList
       list.printList() ;
list.splitList();
         
   }
}

"Get 15% discount on your first 3 orders with us"
Use the following coupon
FIRST15

Order Now