Implement an interface that will allow you to move around

Assignment Help Computer Engineering
Reference no: EM132125647

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.

Reference no: EM132125647

Questions Cloud

Why is rsa believed to be hard to break : Why is RSA believed to be hard to break? I. E. The complexity of what computational problem leads to the belief that it is secure?
Will the packet be forwarded into its base network : If a router is attached to a network with a base IP address of 198.10.0.0/20 and receives a packet addressed to 198.10.10.144.
The four types of e-businesses namely e-marketplace : How does the role of operations vary across the four types of e-Businesses namely e-marketplace, e-service, e-retailers and wholesalers, and e-producers?
What role should platform providers play in social discourse : Do these technology companies have an obligation to understand the impacts they are having on society? Do they have a responsibility to participate?
Implement an interface that will allow you to move around : For this program, you will implement an interface that will allow you to move around a rocket of your own design.
What you as a dba can do to give scott access to his account : If possible, demonstrate what you as a DBA can do to give SCOTT access to his account.
What would be the interest rate : Suppose that you are planning to pay $14500 yearly for 4 years for a car which is $50000 now what would be the interest rate?
Compute net capital gain or net capital loss for year ended : HI6028 Taxation Theory, Practice & Law Assignment, Holmes Institute. Based on this information, determine your client's net capital gain or net capital loss
Prove that your solution is optimal : The machine can mill only one object at a time, but your workers can be polishing in parallel as many objects as you wish.

Reviews

Write a Review

Computer Engineering Questions & Answers

  Mathematics in computing

Binary search tree, and postorder and preorder traversal Determine the shortest path in Graph

  Ict governance

ICT is defined as the term of Information and communication technologies, it is diverse set of technical tools and resources used by the government agencies to communicate and produce, circulate, store, and manage all information.

  Implementation of memory management

Assignment covers the following eight topics and explore the implementation of memory management, processes and threads.

  Realize business and organizational data storage

Realize business and organizational data storage and fast access times are much more important than they have ever been. Compare and contrast magnetic tapes, magnetic disks, optical discs

  What is the protocol overhead

What are the advantages of using a compiled language over an interpreted one? Under what circumstances would you select to use an interpreted language?

  Implementation of memory management

Paper describes about memory management. How memory is used in executing programs and its critical support for applications.

  Define open and closed loop control systems

Define open and closed loop cotrol systems.Explain difference between time varying and time invariant control system wth suitable example.

  Prepare a proposal to deploy windows server

Prepare a proposal to deploy Windows Server onto an existing network based on the provided scenario.

  Security policy document project

Analyze security requirements and develop a security policy

  Write a procedure that produces independent stack objects

Write a procedure (make-stack) that produces independent stack objects, using a message-passing style, e.g.

  Define a suitable functional unit

Define a suitable functional unit for a comparative study between two different types of paint.

  Calculate yield to maturity and bond prices

Calculate yield to maturity (YTM) and bond prices

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd