Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a java program named BuildingSystem.java, in which there is a static method called draw used to draw a simple frame of the building. Drawing

Write a java program named "BuildingSystem.java", in which there is a static method called draw used to draw a simple frame of the building.

Drawing panel is size 500 * 500

Building is at (50,10), size 45 * 100

Gray background

Windows are in color (red = 100, green = 50, blue = 100)

Each window is size 5 * 5

Windows are 10px apart (5 blank pixels between horizontally and vertically)

The leftmost window is 10px away from the leftmost border of the building.

The draw method accepts three parameters: graphics, the x and y coordinate of the top left corner of the building.

Write another Java program "Building.java" to declare a class Building. The blue print of the class Building is as below:

Building State: The x and y coordinates of the top left corner.

Behavior: Building(int newX, int newY)

draw(Graphics g)

moveUp()

moveDown()

moveLeft()

moveRight()

Note: please simply declare the required methods in the class, and let each method print out its own name only. E.g. when draw is called, it prints only "draw is called". We are going to implement these methods in following steps.

Implement the constructor Building() and instance method draw() in "Building.java".

Note: you may need to copy some code from previous step into the draw method. But please access the fields x and y in the draw method.

Write another Java program called as "testBuilding.java". In the main method of "testBuilding.java", please create a DrawingPanel and a Building object with the left corner at (50,50). Then draw the created building by calling the instance method draw of the Building object. 5) After drawing the building, now please let "testBuilding.java" accept the input from user until "q" is pressed.

Call moveUp if user types "i" and press "Enter"

Call moveDown if user types "k" and press "Enter"

Call moveLeft if user types "j" and press "Enter"

Call moveRight if user types "l" and press "Enter"

Hint: You may need to write a do while loop to accept the input. To read one character each time using Scanner, we can follow the code below:

Scanner s = new Scanner(System.in);

char input; input = s.next().charAt(0);

Implement moveUp, moveDown, moveLeft and moveRight by changing the fields x and y in "Building.java"

Modify main method of "testBuilding.java" of previous step let Building object update itself on the window after key "i", "k" , "j" or "l" is pressed. Each time, the movement amount is 10 pixels. For example, when "i" is pressed, the building should move up 10 pixels.

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

Step: 3

blur-text-image

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

7. Identify six intercultural communication dialectics.

Answered: 1 week ago