Pls help random methods to draw shapes

Pls help random methods to draw shapes
0

#1

this is what my assignment is I have to complete it using methods and parameters

The problem can be defined as such:
• A city consists of 3 to 6 buildings (inclusive), randomly chosen. The cityscape
should be centered left to right on the display and ground level should be such
that a 15-story building is centered top to bottom.
• The buildings are of width 70 and should be horizontally centred left to right in
the display
• Each building is a rectangle with 5 to 15 stories (inclusive), randomly chosen.
• Each story has two windows and is of height 30.
revised: 27/09/2018
• Each window is four 10x10 squares (remember, squares are also rectangles) centered within the story.

my code so far I am fine with making the rectangles and windows but I am unsure of how I go about making random sized buildings could someone please help

package Assign_3; 
 
 
import Media.*;                  // for Turtle and TurtleDisplayer 
import java.awt.*;               // for Color objects and methods 
import static java.lang.Math.*;  // for math constants and functions 
import static java.awt.Color.*;  // for Color constants 
 
 
/** This class ... 
  * 
  * @author <your name> 
  * 
  * @version 1.0 (<date>)                                                        */ 
 
public class City { 
  
  private TurtleDisplayer display;
  private Turtle yertle;
     
     
    // instance variables 
     
     
    /** This constructor ...                                                     */ 
     
    public City ( ) {
      
      display = new TurtleDisplayer (yertle,500,500);
      yertle = new Turtle ();
      display.placeTurtle (yertle);
      yertle.setSpeed(1);
      drawBuilding();
      display.close();
         
        // statements including call of method 
         
    }; // constructor 
 
     
     
    /** This method ...                         * */
    
    
      
      
      
    
    private void drawBuilding () {
      drawRectangle(70,301*random()-150);
      yertle.forward(20);
      yertle.left(PI/2);
      yertle.forward(15);
      yertle.right(PI/2);
      drawWindow();
      yertle.forward(30);
      drawWindow();
    }
    
      
      
      
      
      
    
    
    
    private void drawWindow ( ) {
      
      for ( int i=1 ; i<=4 ; i++ ) {
      drawRectangle(10,10);
      yertle.right(PI/2);
    };
      yertle.penUp();
    };
    
    
     
    
    private void drawRectangle ( double width, double height  ) {
      
      yertle.penDown();
      for ( int i=1 ; i<=2 ; i++ ) {
        yertle.forward(width);
        yertle.left(PI/2);
        yertle.forward(height);
        yertle.left(PI/2);
      };
      yertle.penUp();
     
        // local variables 
     
        // statements 
     
    }; // <methodName> 
 
     
     
    public static void main ( String[] args ) { City c = new City(); }; 
 
     
     
}  // <className> 

#2

6 posts were merged into an existing topic: Help me please methods with parameters


#3

#4

Please do not create duplicate topics for the same question(s). In the future, just reply to your original thread. I merged this thread with your original to prevent splitting the discussion. I have also unlisted this duplicate thread.

Thank you.