document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. /**
  2.  *
  3. 2.  Based on this ArrayListNum class, write a Java application for the following purposes:-
  4. •   Test the method insertAtFront() and display () by inserting THREE (3) integers
  5. •   Test the method insertAtBack() and display() by inserting THREE(3) integers:
  6. •   Test the method removeFromBack() and display() by removing TWO(2) element.
  7. •   Calculate the sum
  8. •   Find the minimum and maximum
  9. •   Compute the average
  10. •   Count how many elements are odd and how many are even.
  11.  
  12.  *
  13.  * @author MUHAMMAD AZRI BIN JASNI @ ABDUL RANI
  14.  * @version 27 SEPTEMBER 2012
  15.  */
  16. import java.util.*;
  17. public class javaApp
  18. {
  19.     public static void main (String [] args)
  20.     {
  21.         ArrayListNum listo = new ArrayListNum();//empty list
  22.         Scanner sc = new Scanner(System.in);
  23.         int sum = 0, min=0, max=0, odd=0, even=0;
  24.         double average;
  25.        
  26.         System.out.println("\\nEnter 3 integers to test insertAtFront():");
  27.         for (int i=0;i<3;i++)
  28.             listo.insertAtFront( sc.nextInt() );
  29.         listo.display();
  30.        
  31.         System.out.println("\\nEnter 3 integers to test insertAtBack():");
  32.         for (int i=0;i<3;i++)
  33.             listo.insertAtBack( sc.nextInt() );
  34.         listo.display();
  35.        
  36.         System.out.println("\\nRemoving 2 integers [AUTO] to test removeFromBack():");
  37.         for (int i=0;i<2;i++)
  38.             listo.removeFromBack();
  39.         listo.display();
  40.        
  41.         //Integer element = new Integer(listo.list[0]);
  42.         System.out.println("\\nlisto.length="+listo.length+"\\n");
  43.         int element = listo.list[0];
  44.         min = element;
  45.         max = element;
  46.         for (int i=0; i< listo.length; i++)
  47.         {
  48.             //element = new Integer(listo.list[i]);
  49.             element = listo.list[i];
  50.             sum = sum + element;
  51.             if (min > element)
  52.                 min = element;
  53.             if (max < element)
  54.                 max = element;
  55.             if (element%2==0)
  56.                 even++;
  57.             else
  58.                 odd++;
  59.         }
  60.         average = (sum*1.0) / (listo.length*1.0);
  61.        
  62.         System.out.print("\\nCalculate the sum: "+sum);
  63.         System.out.print("\\nMinimum: "+min);
  64.         System.out.print("\\nMaximum: "+max);
  65.         System.out.print("\\nAverage: "+average);
  66.         System.out.print("\\nNo of element for odd number: "+odd);
  67.         System.out.print("\\nNo of element for even number: "+even);
  68.         System.out.println("\\nEnd Test.");
  69.         sc.close();
  70.     }
  71. }
');