// WhileDemo2.java
// Prints a column of integers and their squares and cubes
// APPLET CODE="WhileDemo2" HEIGHT=300 WIDTH=200
// Includes a double, a cast and a sentinel controlled while structure
import java.awt.*;
import javax.swing.*;

public class WhileDemo2 extends JApplet {
	int n, s, c, cTotal;
	int xPos, yPos;
	double avg;
	boolean go;

	public void init( ) {
		n = 1;
		s = 0;
		c = 0;
		cTotal = 0;
		xPos = 0;
		yPos = 20;
		go = true;
	}

	public void paint( Graphics g ) {
		g.drawString( "number", xPos, yPos );
		g.drawString( "square", xPos + 50, yPos );
		g.drawString( "cube", xPos + 100, yPos );
		g.drawString( "cube average", xPos + 150, yPos );

		yPos = yPos + 25;

		while ( go ) {
			s = n * n;
			c = n * n * n;
			cTotal = cTotal + c;
			avg = ( double ) cTotal / n;

			g.drawString( "" + n, xPos, yPos );
			g.drawString( "" + s, xPos + 50, yPos );
			g.drawString( "" + c, xPos + 100, yPos );
			g.drawString( "" + avg, xPos + 150, yPos );

			if ( avg >= 200 )
				go = false;

			n = n + 1;
			yPos = yPos + 25;
		}
	}
}