Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help, in dire need and no one has been able to help me. The java code is completed just needs to be modified. The

Please help, in dire need and no one has been able to help me. The java code is completed just needs to be modified. The picture for the ball class has been deleted and the code added instead. Full provided code i was given for the "ButtonWorld" class had been provided and updated.

enimage text in transcribed

image text in transcribed

import greenfoot.*;

/** * A button that moves randomly around the World. * * * @author * @version */ public class Button extends Actor { /** * Changes the location of this button approximately * 2% of the time. */ public void act() { if (Greenfoot.getRandomNumber(100)

/** * Sets the location of this Button object to a new (x, y) * coordinate selected at random. The x coordinate wil be in * the range 100 to 500 inclusive, and the y coordinate will * be the range 100 to 300 inclusive. */ public void changeLocation() { setLocation(Greenfoot.getRandomNumber(401) + 100, Greenfoot.getRandomNumber(201) + 100); } }

import greenfoot.*;

/** * A ball with motion controlled by the keyboard and the ability * to remove buttons from the world. * * * @author YOUR NAME * @version */ public class Ball extends Actor { /** * Responds to motion control from the arrow keys and removes * any buttons from the world when it intersects them. */ public void act() { handleKeyPress(); lookForButton(); }

/** * Checks to see if the ball is "touching" an object of the Button class. * If it is, then the ball removes from the World a Button that it touches. * If the ball isn't touching an object of the Button class, then this * method does nothing. */ public void lookForButton() { if (isTouching(Button.class)) { removeTouching(Button.class); } }

/** * Handles input from the arrow keys. */ public void handleKeyPress() { checkLeftArrow(); checkRightArrow(); checkUpArrow(); checkDownArrow(); }

/** * Checks to see if the left arrow key is being pressed. * If it is, then the ball sets its rotation angle to zero degrees * and moves backward 5 units. If it is not being pressed, * this method does nothing. */ public void checkLeftArrow() { if (Greenfoot.isKeyDown("left")) { setRotation(0); move(-5); } }

/** * Checks to see if the right arrow key is being pressed. * If it is, then the ball sets its rotation angle to zero degrees * and moves forward 5 units. If it is not being pressed, * this method does nothing. */ public void checkRightArrow() { if (Greenfoot.isKeyDown("right")) { setRotation(0); move(5); } }

/** * Checks to see if the up arrow key is being pressed. * If it is, then the ball sets its rotation angle to 270 degrees * and moves forward 5 units. If it is not being pressed, * this method does nothing. */ public void checkUpArrow() { if (Greenfoot.isKeyDown("up")) { setRotation(270); move(5); } }

/** * Checks to see if the down arrow key is being pressed. * If it is, then the ball sets its rotation angle to 90 degrees * and moves forward 5 units. If it is not being pressed, * this method does nothing. */ public void checkDownArrow() { if (Greenfoot.isKeyDown("down")) { setRotation(90); move(5); } } }

1. Modify the constructor of the Buttonworld class so that a single Ball object is placed at location (500, 400 and tern Button objects are placed at random locations throughout the world 2. Modify the Bal class so that it counts the number of Button objects it removes. Specifically: o You must declare an instance variable of type int in the Bal class for this purpose o You must initialize this instance variable to zero in the constructor of the Ba class. (You must write this constructor. It has not been provided for you.) o You must increment this instance variable at the appropriate point in the lookForButton method of the Ball class. 3. Modify the Ball class so that it has two different images that it can use. Its default image, the one that it starts with, is steel-ball.png. The second image it can use is gold- ball.png. Specifically: o You must declare two instance variables of type Greenfoot Image in the Ball class for this purpose o You must initialize these instance variables to the appropriate images in the constructor of the Ball class o You must set the object's current image to steel- ball.png in the constructor of the Ball class. 4. Modify the Ball class so that it changes its image to gold ball.png as soon as it has removed five or more buttons. It keeps this image for the remainder of execution. Specifically: o You must modify the lookForButton method in the Ball class. 5. Modify the Ball class so that it stops the scenario execution once it has removed all ten Button objects. Specifically o You must create a method named checkToStop in the Ball class that checks to see if all ten buttons have been removed. If so, the scenario is stopped o You must modify the act method of the Ball class to call the checkToStop methood

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

Database Processing

Authors: David M. Kroenke, David Auer

11th Edition

B003Y7CIBU, 978-0132302678

More Books

Students also viewed these Databases questions

Question

Describe agility (for software projects) in your own words.

Answered: 1 week ago