Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

To make the body and jet line up correctly with the nose, you need to complete the methods getBodyXPos(), getBodyYPos(), getJetXPos() and getPosJetYPos() in the

To make the body and jet line up correctly with the nose, you need to complete the methods getBodyXPos(), getBodyYPos(), getJetXPos() and getPosJetYPos() in the Rocket class.

When you complete the helper methods in i. to iv. below, your methods must not use fixed numbers for the positions or dimensions of the rocket parts. Rather, you must use appropriate methods from the classes Circle, Triangle and Square.

  • i.Complete the method getBodyXPos() so that it returns an appropriate value, relative to the position of the nose.

  • ii.Complete the method getBodyYPos() so that it returns an appropriate value, relative to the position of the nose.

  • iii.Complete the method getJetXPos() so that it returns an appropriate value, relative to the position of the body.

  • iv.Complete the method getJetYPos() so that it returns an appropriate value, relative to the position of the body.

When you have correctly completed these private helper methods, the parts of the rocket should appear properly assembled in the launch position.

image text in transcribed

import ou.*; /** * Class Rocket allows a representation of a rocket to be created in the Shapes * Window, and for it to move up the screen. * * This class is incomplete. * * @author (M250 Course Team) * @version (1.1) */ 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 0; }

private int getBodyYPos() { //to be written in Q1(a)(ii) return 0; } private int getJetXPos() { //to be written in Q1(a)(iii) return 0; }

private int getJetYPos() { //to be written in Q1(a)(iv) return 0; }

X 0 Shapes Figure 3 - Correctly positioned parts of rocket X 0 Shapes Figure 3 - Correctly positioned parts of rocket

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

Introduction To Data Mining

Authors: Pang Ning Tan, Michael Steinbach, Vipin Kumar

1st Edition

321321367, 978-0321321367

More Books

Students also viewed these Databases questions

Question

What's the quickest way someone can lose your trust?

Answered: 1 week ago