For this program you will implement an interface that will


Rocket Class: Keyboard Event Handling

Introduction

For this program, you will implement an interface that will allow you to move around a rocket of your own design.

You will need to implement your own classes for the rocket and a test driver, but you will also be able to use the same Blobz.jar external JAR file as for Program 3, which contains useful utilities for creating a graphics context and for supporting your calculations.

The only output of the program should be your rocket displayed in the sandbox, and you should be able to move it around using the up, left, and right arrow keys on your keyboard. One example of a simple rocket is shown here:

NetBeans Project Setup

1. Create a Java application project called "RocketSim" in NetBeans. Edit the "packaging" properties so that the source (.java) files will be included in the JAR file.

2. Using the "Files" tab in NetBeans, look at your "src" folder. If it is empty, create a new Java package called "rocketsim". If NetBeans already created that package for you, then skip this step.

3. Now, create two separate Java class files inside the rocketsim package. The first file should be called Rocket.java. This will hold your Rocket class. The second file should be called RocketTest.java. This will be the test driver class. There should be a main() method in the RocketTest class, but not in the Rocket class. If NetBeans automatically created a main() method in the Rocket class for you, you should delete that main() method.

4. In the Project Properties for your project, select the "Libraries" category. Then, press the "Add JAR/Folder" button. A dialog will appear where you will be able to find and select the Blobz.jar file on your system. Select it. You should now see that Blobz.jar is included in the "Compile-time Libraries" window on the dialog. Select "OK". Your project is now set up to use Blobz.jar.

Program Development

1. The Rocket class must extend the PolyBlob class and also implement the BlobAction interface. Both of these are in the Blobz.jar file and should be imported into your program from the blobz package.

Provided here:Link to Blobz.jar

file storage

2. The first statement in your Rocket constructor should be: "super(0,0,0);" This will create a stationary PolyBlob in the upper left corner of the sandbox. Then, use the Rocket's setLoc() method, which is inherited from Blob, to set the location to the input location specified by the input parameters to the constructor. The constructor should have 3 input parameters: an int x-coordinate, an int y-coordinate, and the sandbox that your RocketTest test driver instantiated.

3. Your rocket shape will be defined by the polygon you set using the setPolygon() method. You can create your shape on paper and then use those values to initialize the coordinates of the Point[] array that you will pass to setPolygon(). Remember, the coordinates are relative to the origin, which is point (0,0).

4. Since the Rocket class implements the BlobAction interface, the Rocket class must have a public void keyAction(KeyEvent e) method. This method should have separate processing blocks for handling key codes 37 (left arrow), 38 (up arrow), and 39 (right arrow).

5. The Rocket class should also have these instance variables: private double angle = 0.0; private final double delta = 0.15; and private final double speed = 5.0; .

6. The rocket shape that you specify can have as many vertices as you wish. However, no value in the polygon arrays can be less than -10 or greater than +10. Also, when your rocket is first placed in the sandbox, it should be oriented so that the direction of forward motion is to the right as one looks at the screen. This is the direction that should correspond to the initial value of angle = 0.0.

7. The variable "angle" keeps track of the orientation of your rocket. It is initially set to zero, which represents pointing to the right as you look at the screen. Turning to the right will involve adding "delta" to the current angle. Turning to the left will involve subtracting delta from the current angle. You will need to add or subtract 2*PI as appropriate to keep the current angle within the range from 0 to 2*PI. Once you determine what the new angle should be, you should update the rocket's orientation using the setAngle() method.

8. The forward motion block of your keyAction() method should retrieve the current x and y coordinates of your rocket's location, then adjust the locations using the "speed" configuration parameter and the current value of "angle" (which was set to 0.0 initially in the rocket class constructor), and finally should update the location of the rocket using the setLoc() method.

9. The RocketTest class must implement the BlobGUI interface and should have a main() method that contains only the line "new RocketTest()". This is a call to the constructor for the class.

10. The constructor for the RocketTest class should take no input parameters, but it should perform the following actions: (a) create a sandbox; (b) set the sandbox to be in "flow" mode; (c) set the frame rate to 15 frames per second; and (d) pass a reference to itself to the sandbox by running the sandbox's init() method, for example, "sb.init(this)", where "sb" represents the sandbox instance you have created.

11. The RocketTest class should also have a generate() method, which it is required to have since it implements the BlobGUI interface. This generate method will be called every time the user presses the "Start New Game" button on the GUI. The generate() method should instantiate a new Rocket at the location that is at the center of the sandbox. There are several ways to do this. One way to do this is to hard-code the location of the center knowing that the sandbox is 600 x 600 pixels in size. Also, don't forget that the Rocket constructor should have three input parameters, as described in step 2 above in this section. Once the rocket is instantiated, the generate() method should then add it to the sandbox using your sandbox's addBlob() method.

Program Testing

1. Create a folder called "prog4" on your desktop and put a copy of your RocketSim.jar executable JAR file in this folder.

2. Also create a folder called "lib" inside the prog4 folder and put a copy of the Blobz.jar file into the lib folder.

3. Open a command window and navigate to the prog4 folder on your desktop. For most systems, you should be able to get there by entering: "cd Desktop\prog4" (Windows) or "cd Desktop/prog4" (Mac/Linux).

4. Now, run your program using the command: "java -jar RocketSim.jar". Your program should run. If it does not, fix the problem and keep testing until you meet with success.

What to Submit

1. Submit on Webcourses ONLY the RocketSim.jar file that you have successfully tested from the command line, as described above. Do not submit the lib folder or Blobz.jar.

2. If you make improvements to your program, you may submit again as many times as you like, provided the submissions are prior to the deadline for this assignment. Please note that Webcourses will add a suffix number to the file name for the second and later submissions, but this is not a problem. The graders will know how to handle this situation.

3. Your JAR file must contain the Rocket.java and RocketTest.java source files. Both of these files must contain a file header in the following format, so that we know it is your code.

Request for Solution File

Ask an Expert for Answer!!
Computer Engineering: For this program you will implement an interface that will
Reference No:- TGS02919099

Expected delivery within 24 Hours