Help me please methods with parameters

Write a Java program to draw a cityscape as seen below. The city consists of some number of buildings. Each building has multiple stories. Each story has windows. Your program should draw a random cityscape as defined below using Turtle Graphics and methods with parameters.

page1image17109888|431.999978x376.649567

The problem can be defined as such:

  • A city consists of 3 to 6 buildings (inclusive), randomly chosen. The cityscapeshould be centered left to right on the display and ground level should be suchthat a 15-story building is centered top to bottom.
  • The buildings are of width 70 and should be horizontally centred left to right inthe 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.

BELOW IS MY CODE SO FAR COULD SOMEONE PLEASE HELP ME HOW TO ACTUALLY DRAW THE BUILDING

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>

thanks for your reply
I know how to use the methods to draw shapes and set parameters for the shapes but I don’t know how to use the random function in determining a random rectangle with shapes inside it

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> 

I haven’t done java but you would import a library that takes care of random numbers for you. Probably a subset of a match library. Then when you start drawing, you would insert values returned form random numbers.

I think the math library will take care of random numbers for me I just don’t know how to actually implement it in my code

Remember google is the source of knowledge. Here is an example.

I am still confused honestly I am 3 weeks into coding so I don’t really know that much but I have looked over that and I can’t figure out how to implement it in my problem

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);
     yertle.moveTo(0,-225);
     drawBuilding();
     display.close();
        
       // statements including call of method 
        
   }; // constructor 

    
    
   /** This method ...                         * */
   
   
     
     
     
   
   private void drawBuilding () {
     drawRectangle(70,450);
     for ( int i=1 ; i<=15 ; i++){
     yertle.forward(20);
     yertle.left(PI/2);
     yertle.forward(15);
     yertle.right(PI/2);
     drawWindow();
     yertle.forward(30);
     drawWindow();
     yertle.left(PI/2);
     yertle.forward(15);
     yertle.right(PI/2);
     yertle.backward(50);
     } 
     
     
   }
   
     
     
     
     
     
   
   
   
   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> 

this is my new code

I’ve just moved this to the Help section as it’s not JavaScript, carry on :wink:

Hi. Moving away from the Java code, let’s try to do this in pseudo code. Could you reframe the problem and what you think the solution should be in pesudo-code?