CMIS 102A
Using the ForLoopsTest.java
Calculate and output the average of the numbers.
The average of a bunch of numbers is the sum of them divided by the
number of them.
Modify it further to find the smallest and largest of the inputted
numbers.
Modify it further to count the number of positive numbers and the
number of negative numbers.
Modify it further to count the number of odd numbers and the number of
even numbers.
Modify the applet so it draws random lines.
g.drawLine(x1,y1,x2,y2) arguments are the x and y coordinates of the
two endpoints of the line. These can be random numbers between 1 and
size of the applet area. The Math.random() method returns a random
real number between 0 and 1 which can be multiplied by the applet size
to give a random real number between 0 and the applet size. Cast the
double value to an int for the drawLine method's argument.
E.g.
(int)(Math.random()*400)
gives a random int between 0 and 399.
(int)(Math.random()*getWidth())
gives a random int between 0 and the width of the applet area.
(int)(Math.random()*getHeight())
gives a random int between 0 and the height of the applet area.
Run it with 1000 lines to draw.
Run it with 100,000 lines to draw.
Now modify it to draw random points. There is no drawPoint method. A
point is a line from a point to itself, so use the same x and y twice
for the two endpoints of the line to draw a point.
The points will be uniformly distributed in the applet area.
Draw 100,000 points.