Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have a code for the building need help making the random skyline now with 3 to 6 buildings different height. my code is: package

I have a code for the building need help making the random skyline now with 3 to 6 buildings different height.

my code is:

package Assign_3;

import Media.*; // for Turtle and TurtleDisplayer import java.awt.*; // for Color objects, constructor and methods import static Media.Turtle.*; // for Turtle speeds import static java.lang.Math.*; // for math constants and functions import static java.awt.Color.*; // for Color constants

*/

public class Cityscape { // instance variables private TurtleDisplayer display; private Turtle squirtle; /** This constructor ... */ public Cityscape ( ) { // statements including call of method display = new TurtleDisplayer (squirtle,500,500); squirtle = new Turtle (0); display.placeTurtle (squirtle); squirtle.moveTo(0,-225); drawBuilding(); display.close(); }; private void drawBuilding ( ) { drawRectangle(70,450); for ( int i=1 ; i<=15 ; i++){ squirtle.forward(20); squirtle.left(PI/2); squirtle.forward(15); squirtle.right(PI/2); drawWindow(); squirtle.forward(30); drawWindow(); squirtle.left(PI/2); squirtle.forward(15); squirtle.right(PI/2); squirtle.backward(50); } }; //drawBuilding private void drawWindow ( ) { for ( int i=1 ; i<=4 ; i++ ) { drawRectangle(10,10); squirtle.right(PI/2); } squirtle.penUp(); }; //drawWindow private void drawRectangle ( double width, double height ) { squirtle.penDown(); for ( int i=1 ; i<=2 ; i++ ) { squirtle.forward(width); squirtle.left(PI/2); squirtle.forward(height); squirtle.left(PI/2); }; squirtle.penUp(); }; // drawRectangle

public static void main ( String[] args ) { Cityscape s = new Cityscape(); };

} // Cityscape

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.

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.

  • Each window is four 10x10 squares (remember, squares are also rectangles)

centered within the story.

Hints:

  • Use a TurtleDisplayer with a 500x500 canvas: display = new TurtleDisplayer(yertle,500,500);

    which creates the display and places yertle on the display.

  • Use a FAST Turtle

  • Consider using methods to draw the city of some number of buildings, draw a

    building of some number of stories, draw a window and draw a rectangle each

    with appropriate parameters

  • Build your program bottom-up, that is, initially simply draw a rectangle, then

    draw a window, then a building and finally a city.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Do all antidepressants have the same clinical effect?

Answered: 1 week ago