Complete Star

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
Historical topic: Java appletsModern web browsers do not run Java applets. The Applet API was deprecated for removal before Java 25 and was removed in Java 26. Treat applet examples on this page as historical object-oriented/GUI examples; for new desktop interfaces use Swing where appropriate or JavaFX/OpenJFX.

Answer:

This is a type cast. It notifies the compiler that it is OK to convert the floating point value to its right into an int.

Complete Star

Here is the complete program that draws a single star in the center of the rectangle:

import java.applet.Applet ;
import java.awt.* ;
import java.lang.Math ;

public class SnowFlakeBasic extends Applet
{
  Graphics graph;
   
  private void drawStar( int x, int y, int size )
  {
    int endX, endY ;
    
    // Six lines radiating from (x,y)
    for ( int i = 0; i<6; i++ )
    {
      endX = x + (int)(size*Math.cos( (2*Math.PI/6)*i ));
      endY = y - (int)(size*Math.sin( (2*Math.PI/6)*i ));
      graph.drawLine( x, y, endX, endY );
    }
  }
         
  public void paint ( Graphics gr )
  { 
    graph = gr;
    int width  = getSize().width;
    int height = getSize().height;
    int min;
    
    setBackground( Color.white );
    gr.setColor  ( Color.blue  );
    
    if ( height > width )
      min = height;
    else
      min = width;
      
    drawStar( width/2, height/2, min/4 );
  }
}

There is nothing recursive about it yet. This will come next.

QUESTION 9:

Next, to draw the snowflake, stars are drawn at the end of the six lines. Do you already know where these locations are?

Embedded Java applet removed: modern browsers do not support Java applets. The surrounding source code is retained for historical study.