I'm trying to print out an array of 10 objects. For some reason though, when I print out the array, there are anywhere from 15 to 22 elements in the array. I can't figure out why. Can someone please point me in the right direction?
import java.util.Random;
public class Main {
public static void main( String[] args ) {
Shape[] myShapes = new Shape[10]; //Array of 10 shapes
Random rand = new Random(); //Random number generator
int shape, x1, y1, x2, y2, x3, y3;
double radius;
for( int i = 0; i < 10; i++ ) {
shape = rand.nextInt(3); //randomly select shape
switch( shape ) {
case 0: //Triangle
x1 = rand.nextInt(101);
y1 = rand.nextInt(101);
x2 = rand.nextInt(101);
y2 = rand.nextInt(101);
x3 = rand.nextInt(101);
y3 = rand.nextInt(101);
myShapes[i] = new Triangle( x1, y1, x2, y2, x3, y3 );
System.out.println("Triangle: " + myShapes[i].area());
case 1: //Rectangle
x1 = rand.nextInt(101);
y1 = rand.nextInt(101);
x2 = rand.nextInt(101);
y2 = rand.nextInt(101);
myShapes[i] = new Rectangle( x1, y1, x2, y2 );
System.out.println("Rectangle: " + myShapes[i].area());
case 2: //Circle
radius = rand.nextDouble()*100.0;
x1 = rand.nextInt(101);
y1 = rand.nextInt(101);
myShapes[i] = new Circle( radius, x1, y1 );
System.out.println("Circle: " + myShapes[i].area());
}
}
}