Lab 7: Working with Arrays.

Lab Overview:

In this lab you will write an applet that operates on an array of integers and performs 4 statistical operations on it: minimum, maximum, average (Arithmetic mean) and Standard deviation. You will have to write the code of Standard Deviation from scratch (rather, use the one you have already written from scratch as the prelab.)

Your applet should also display the numbers in the array, one at a time.

The Java Applet:

  1. Start/Launch Eclipse and snarf a new the labs/07_Arrays project

  2. You will need to add awb.jar to your build path by going to project Properties, then select Java Build Path, click Libraries, and then select Add JARs and find the awb.jar in your project.

  3. To the existing ArrayStats program you need to add one button "Standard Deviation" which on clicking displays the standard deviation of the array of numbers. Also instead of using a double array you will use an integer array.

  4. You will need:
    1. One int array of size 100.
    2. One IntField for the user to enter the numbers in the array one by one similar to one already there in ArrayStats.
    3. Two TextFields.
      1. One TextField to display the instruction stating "Enter Value and then press Store Button".
      2. One TextField which displays all the output of the program - Mean, Standard Deviation, Extremes and values in the array. This TextField is same as in except that it will also display the Standard Deviation of the array.
    4. Six Buttons.
      1. One Button called Store which when clicked takes the value (entered by the user) in IntField as input and stores it in the array.
      2. One Button called Show which when clicked displays each value of the array one by one in TextField.
      3. One Button called Mean which when clicked displays the mean of the values in the array in the TextField.
      4. One Button called Extremes which when displays the minimum and maximum value in the array in TextField.
      5. One Button called Standard Deviation to display the Standard Deviation of the values in the array in TextField.
      6. One Button called Clear which clears the array.

  5. For each of the buttons Show, Extremes, Mean, Standard Deviation you may assume that they are clicked only after at-least one value is stored in the array

  6. In the ArrayStatsExtendedclass that you snarfed, add the Standard Deviation method from your Prelab. For rest of the methods you need to modify the ones in to use an int array instead of double so that you return an int value and accept int array as parameter instead of double. (The methods which return the mean and the one you wrote for Standard Deviation will be the exceptions, they will return a double each.)

  7. Add code to create and add to the screen a button called "Standard Deviation". Make sure you add an ActionListener to all your Buttons.

  8. Add code to define operation of the Standard Deviation button. When the user clicks the button, your program should call your standardDeviation method and display the output in a the output TextField.

  9. After you complete your code, taking some from the applet and that for the Standard Deviation operation. You need to Build and Run your project/ lab7. To do this, Right-click on the lab7 project and choose “Run as” -> “Java Applet” .

  10. The ArrayStatsExtended.html file will display the applet.You need to edit it. (DO NOT Double-Click or try to open it with the Eclipse Web Browser. This is the Default option (unfortunately) and will cause Eclipse to FREEZE!) Edit this file (Right-Click -> Open with-> Text Editor) to include your name, netId and other information ( Collaborators, Resources used..).


Make sure to test several possible input values when you run your applet via Eclipse. If your applet gives incorrect results for trivial sets of numbers, then there is a problem in your subroutine. Go back and check your computation for logic errors, fix them, and recompile. (For computational errors, check if the while loops are running for the exact number of times as you want them to and then check if any operations need parentheses around them.

Link to your applet


Submit your and ArrayStatsExtended.html files using Eclipse. See the Ambient submit instructions. You should submit under class cps001, assignment name lab7.

Also, make sure that your applet also works over the Internet at the above mentioned link.

Siddhesh Sarvankar (