Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

i need to complete the method moveRocketBy(). marked in bold. The method should move the rocket upwards by the amount given by the method's argument.

i need to complete the method moveRocketBy(). marked in bold. The method should move the rocket upwards by the amount given by the method's argument. In other words, the method needs to change the y-positions of the parts of the rocket.

To do this, first set the nose position, and then set the body and jet positions relative to the nose and body, respectively. You must make use of the methods you wrote for part a., as well as other methods.

--------------------------------------------------------------------------------------------

public class Rocket { private Triangle nose; // represents the rocket's nose cone private Square body; // represents the rocket's body private Circle jet; // represents the blast from the rocket's engine

/** * Constructor for objects of class Rocket */ public Rocket(Triangle t, Square s, Circle c) { //first, we store references to the workspace shape objects this.nose = t; this.body = s; this.jet = c;

//sets the initial positions of the nose. //The other parts need to be set relative to these positions. this.nose.setXPos(50); this.nose.setYPos(300);

//sets the body relative to the nose, using the helper methods this.body.setXPos(getBodyXPos()); this.body.setYPos(getBodyYPos());

//The jet is invisible to begin with, because it uses //the background colour of WHITE, but you can use BLACK //to help you see it while testing this.jet.setColour(OUColour.WHITE); this.jet.setDiameter(10);

//sets the jet position relative to the body, using the helper methods this.jet.setXPos(getJetXPos()); this.jet.setYPos(getJetYPos()); }

private int getBodyXPos() { //to be written in Q1(a)(i) return this.body.getXPos(); }

private int getBodyYPos() { //to be written in Q1(a)(ii) return this.body.getYPos(); } private int getJetXPos() { //to be written in Q1(a)(iii) return this.jet.getXPos(); }

private int getJetYPos() { //to be written in Q1(a)(iv) return this.jet.getYPos(); }

/** * Moves the nose of the receiver * by anInt units. * Moves other rocket components relative to the * position of the nose. */ public void moveRocketBy(int anInt) { //to be written in Q1(b) }

-------------------------------------------------------------------------------------------------------------

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 Kroenke

11th Edition

0132302675, 9780132302678

More Books

Students also viewed these Databases questions

Question

Was ignoring the problem an option? Why?

Answered: 1 week ago

Question

6. The cost of the training creates a need to show that it works.

Answered: 1 week ago