Ask Computer Engineering Expert

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.

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M93113113

Have any Question?


Related Questions in Computer Engineering

Does bmw have a guided missile corporate culture and

Does BMW have a guided missile corporate culture, and incubator corporate culture, a family corporate culture, or an Eiffel tower corporate culture?

Rebecca borrows 10000 at 18 compounded annually she pays

Rebecca borrows $10,000 at 18% compounded annually. She pays off the loan over a 5-year period with annual payments, starting at year 1. Each successive payment is $700 greater than the previous payment. (a) How much was ...

Jeff decides to start saving some money from this upcoming

Jeff decides to start saving some money from this upcoming month onwards. He decides to save only $500 at first, but each month he will increase the amount invested by $100. He will do it for 60 months (including the fir ...

Suppose you make 30 annual investments in a fund that pays

Suppose you make 30 annual investments in a fund that pays 6% compounded annually. If your first deposit is $7,500 and each successive deposit is 6% greater than the preceding deposit, how much will be in the fund immedi ...

Question -under what circumstances is it ethical if ever to

Question :- Under what circumstances is it ethical, if ever, to use consumer information in marketing research? Explain why you consider it ethical or unethical.

What are the differences between four types of economics

What are the differences between four types of economics evaluations and their differences with other two (budget impact analysis (BIA) and cost of illness (COI) studies)?

What type of economic system does norway have explain some

What type of economic system does Norway have? Explain some of the benefits of this system to the country and some of the drawbacks,

Among the who imf and wto which of these governmental

Among the WHO, IMF, and WTO, which of these governmental institutions do you feel has most profoundly shaped healthcare outcomes in low-income countries and why? Please support your reasons with examples and research/doc ...

A real estate developer will build two different types of

A real estate developer will build two different types of apartments in a residential area: one- bedroom apartments and two-bedroom apartments. In addition, the developer will build either a swimming pool or a tennis cou ...

Question what some of the reasons that evolutionary models

Question : What some of the reasons that evolutionary models are considered by many to be the best approach to software development. The response must be typed, single spaced, must be in times new roman font (size 12) an ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As