Part 1 asks you to solve a small programming problem involving 3 numbers.
You should be able to complete Part 1 in 10 minutes or less.
Use the techniques you learned from the Guided Tour to create a suitable directory for this lab and start jEdit. You might consider opening a terminal and entering the following commands:
cd Documents/cse1020
mkdir lab03
cd lab03
jedit &
Recall that a utility class has all attributes and methods marked static. To use an attribute or method of a utility class, you must use the name of the class followed by a period followed by the name of the attribute or method.
java.lang.Math is a utility class that groups together commonly used mathematical attributes and methods. Its API is documented here.
Usually, we refer to the name of the class as simply Math. It is organized into the package named java.lang. Java will automatically import the package java.lang if it is required, so you do not need to (and should not) import java.lang.Math.
You could use the Math utility to compute the area of a circle:
double radius = 5.0;
double area = Math.PI * radius * radius;
or, if you prefer to use a method to compute the radius squared:
double radius = 5.0;
double area = Math.PI * Math.pow(radius, 2);
Notice that you must use Math. before the attribute or method name.
Write a program named SimpleStats that reads in three integers from the command line and outputs the minimum, maximum, average (computed as a real number) and standard deviation of the three numbers.
The (sample) standard deviation of a set of measurements is a measure of the variability or dispersion of the measurements around the average value. For a sample size of 3, the formula for the standard deviation is:
A suitable starting program is shown below:
For this small example program, we will simply output the results on four separate lines:
java SimpleStats -1 0 1
min = -1
max = 1
avg = 0.0
std = 1.0
java SimpleStats 7 10 15
min = 7
max = 15
avg = 10.666666666666666
std = 4.041451884327381
Submit your program using the command:
submit 1020 L03 SimpleStats.java