Hello! I'm supposed to write a program that starts by drawing a 200 X 200 square at the top-left corner of the monitor.
Continue drawing squares that become steadily smaller as they are displayed to right side of each preceding square.
The bottom of the square stays at the same level. Each square is 25 percent smaller than the previously drawn square.
Start with the student version, shown below.

In the student version you are provided with a completed main method. This method is designed to execute graphics application, which done by completing the Windows class.
Make no changes to the main method.

Inside the Windows class, you will need to use a paint method that controls the graphics output with an object of the Graphics class.
You will also need to create a method, called drawSquare, which actually draws the squares and calls itself recursively until the base case is reached.

The recursive process exits when it is true that either the square size becomes smaller than four pixels or the border of the monitor is reached.
You must be aware that only full-sized squares must be displayed. Keep this in mind as you determine if you are reaching the border of the monitor.

80 Point Version

The 80 point version draws one set of squares from left to right, starting with a 200X200 square
that is drawn with a top-left corner at coordinate (0,100). Each square is drawn with a 10 pixel space between the squares.

100 Point Version

The 100 point version draws a second set of squares in the same manner as the 80 point version,
but this time the large square start on the right side and successive squares are drawn moving to the left side of the screen.

My code so far:

import java.awt.*; 
import java.awt.event.*; 

public class lab19b 
public static void main(String args[]) 
Windows win = new Windows(); 
win.addWindowListener(new WindowAdapter() {public void 
windowClosing(WindowEvent e) {System.exit(0);}}); 
class Windows extends Frame{		
public void drawSquare(Graphics g, int left, int top, int width, int height){    
boolean ok = checkDims(left, width);   
 if(!ok) return;     
g.drawRect(left, top, width, height);    
 int newLeft =left+width+10; 	   
 int newTop = 100;				    int newWidth= Math.round(width * 0.75);  		    int newHeight= Math.round(height * 0.75);  	    
drawSquare(g, newLeft, newTop, newWidth, newHeight);}    boolean checkDims(int left, int width) 
if(width<4 && left+width<1000)   
 return true; }  

I know I am supposed to use a float on newwidth and new height, but I really don't know how. Also, could someone tell me if I am on the right track, or give me a clue? Thank you!

How many other forums did you post this question on? I believe you got several responses on JB already, if you haven't checked yet.

p.s. You should capitalize your class names.

Here, add this code to the paint method:

g.drawString("DO YOUR OWN HOMEWORK",10,10);

It's not hard. Keep track of the size multiply it by .25 and you got your new size.

This article has been dead for over six months. Start a new discussion instead.