Page 612 - Introduction to Programming with Java: A Problem Solving Approach
P. 612

                578 Chapter 14 Exception Handling
 /************************************************************
*
NumberList.java
Dean & Dean
This inputs numbers and calculates their mean value.
************************************************************/
*
*
*
import java.util.Scanner;
public class NumberList
{
}
// end class NumberList
private int[] numList = new int[100]; // array of numbers
private int size = 0;
// number of numbers
//*********************************************************
public void readNumbers()
{
}
// end readNumbers
{
}
// end getMean
Scanner stdIn = new Scanner(System.in);
String xStr;
int x;
// user-entered number (String form)
// user-entered number
System.out.print("Enter a whole number (q to quit): ");
        Apago PDF Enhancer
while (!xStr.equalsIgnoreCase("q"))
xStr = stdIn.next();
{
}
x = Integer.parseInt(xStr);
numList[size] = x;
size++;
System.out.print("Enter a whole number (q to quit): ");
xStr = stdIn.next();
// end while
//*********************************************************
public double getMean()
int sum = 0;
for (int i=0; i<size; i++)
{
}
sum += numList[i];
return sum / size;
Figure 14.14b
NumberList class that computes mean of input numbers














































   610   611   612   613   614