Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

    (1 mark)

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

    (2 marks)

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

    (3 marks)

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

    (2 marks)

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

However, because the colour of the jet is OUColour.WHITE it will not be visible in the Graphical Display. You can set it to OUColour.BLACK in order to see where it is, as has been done in Figure 3.

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; }

/** * 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) }

/** * Sets the diameter of the receiver's jet to * 6, alters its xPos so its centre aligns with the body centre * and sets its colour to red. */ public void pulse1() { //to be written in Q1(c)(i) }

/** * Sets the diameter of the receiver's jet to * 12, alters its xPos so its centre aligns with the body centre * and sets its colour to orange. */ public void pulse2() { //to be written in Q1(c)(ii) }

/** * Sets the diameter of the receiver's jet to * 24, alters its xPos so its centre aligns with the body centre * and sets its colour to red. */ public void pulse3() { //to be written in Q1(c)(iii) }

/** * Simulates the ignition of the rocket's jets */ public void ignition() { //to be written in Q1(d) }

/** * Moves the entire rocket in a loop repeated * 100 times, animating the jet as it goes, so the rocket * moves upwards by speed units every 4th iteration */ public void animateRocket(int speed) { //to be written in Q1(e) }

/** * Prompts the user to enter the number of units they want the * rocket to move upwards at a time (speed) * * If the number of units provided would eventually cause the tip of the * nose to go past the top of the Graphical Display, the user * is informed via a dialogue box that the rocket will not launch. * * Otherwise the rocket launches as required. */ public void launch() { //to be written in Q1(f) }

/** * Causes execution to pause by time number of milliseconds */ public void delay(int time) { try { Thread.sleep(time); } catch (Exception e) { System.out.println(e);

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

DNA Databases

Authors: Stefan Kiesbye

1st Edition

0737758910, 978-0737758917

More Books

Students also viewed these Databases questions

Question

python sum dice generator

Answered: 1 week ago

Question

explain what is meant by the terms unitarism and pluralism

Answered: 1 week ago