Hi I need help to developing a java porogram I have provided
Hi! I need help to developing a java porogram. I have provided the detail to thr overall program bellow:
AsteroidField: Inheritance In Action
For program, you will use inheritance to develop an Asteroid class that satisfies certain requirements. You will also develop a separate AsteroidField test driver class to create a field of asteroids. Your test driver will use the \"Blobz.jar\" external JAR file discussed in lecture to display your asteroid field in a dynamic simulation context. The output of the program should appear as shown below, with the asteroids all flowing across the field of view in all directions. When the asteroids move offscreen, they will reappear near the opposite corners as described for the \"flow\" mode discussed in lecture.
To run the simulation, press the \"Start New Game\" button. The \"Pause/Unpause\" button will pause and unpause the motion of the objects. Press \"Stop\" to end the simulation. You can press \"Start New Game\" to start over while the simulation is running or after the \"Stop\" button has been pressed, but you must unpause first if the simulation has been paused.
Test Folder Setup
The javadocs folder contains the Java API documentation for the classes in Blobz.jar. This documentation will be useful to you as you build the various parts of your Asteroids game. To view the javadocs, go into that folder and open the index.html file in your browser. Bookmark the page so it is easy to find later. From this page, you will be able to view the Javadocs for all classes in the Blobz package.
Netbeans Project Setup
1. Create a Java application project called \"AsteroidField\" in NetBeans. Edit the \"packaging\" properties so that the source (.java) files will be included in the JAR file.
2. 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. Create an Asteroid.java class file in your project for your program. This class must satisfy the following requirements:
(a) it must extend the PolyBlob class, so that it inherits from PolyBlob, which in turn inherits from Blob. The class will will have only a constructor and no other methods.
(b) the constructor must take these three input parameters as arguments: (i) an int that represents the x-component of the asteroid\'s velocity vector; (ii) an int that represents the y-component of the asteroid\'s velocity vector; and (iii) a double that represents the angular rotation rate.
(c) the constructor must set the asteroid to start at the offscreen location (-100, -100), since we will be using \"flow\" mode, as discussed in lecture.
(d) the constructor must also initialize the asteroid\'s velocity vector with the velocity component values that the constructor receives as input.
(e) the constructor must create a random simple polygon (no lines crossing) shape for the asteroid that has between 5 and 9 sides and is between 10 and 30 pixels in diameter, as discussed in lecture. When displayed, the shape must not have any lines that cross.
2. Create a separate AsteroidField.java test driver class to create a field of asteroids. This class must satisfy the following requirements:
(a) it must implement the BlobGUI interface, as explained in lecture.
(b) it must have a one-line main() method that instantiates the class, as follows:
(c) the constructor for the class must perform the following actions:
(i) create a sandbox object;
(ii) set the sandbox to \"flow\" mode;
(iii) set the sandbox to run at 15 frames per second; and
(iv) initialize the sandbox by passing \"this\" (the AsteroidField object) to the sandbox\'s init() method.
(d) the class must contain a generate() method, which is required by the BlobGUI interface. The generate() method must perform the following actions:
(i) it must create 10 asteroids using the velocity components and rotational values described here;
(ii) it must randomly choose x and y velocity components for each asteroid, where the x and y components are chosen independently of each other and where each of these values is an integer that may range from -3 to +3, but where zero values are disallowed, all as discussed in lecture;
(iii) it must randomly choose a rotation value of either -.1 or +.1 for each asteroid, with equal probability. Values in between -.1 and +.1 are not permitted; and
(iv) it must add each asteroid to the sandbox.
3. Run and debug your program in NetBeans until it does what it is supposed to do.
4. Clean and build your program. This will create a AsteroidField.jar file in your project\'s \"dist\" folder. You should be able to drill down in the dist folder in the \"Files\" tab and confirm that your source .java files are included in the JAR file. If you do not have a \"Files\" tab, you can get one from the \"Window\" menu at the top of the NetBeans window.
Program Testing
1. Using whatever file manager your system has, copy your AsteroidField.jar file from your project\'s \"dist\" folder and paste the copy into the \"Test\" folder (but not in the \"lib\" subfolder) that you created on your desktop in the \"Test Folder Setup\" section of these instructions. The Test folder on your desktop should now look like this:
2. Open a command window and navigate to the Test folder on your desktop. For most systems, you should be able to get there by entering: \"cd Desktop\\Test\" (Windows) or \"cd Desktop/Test\" (Mac/Linux).
3. Now, run your program using the command: \"java -jar AsteroidField.jar\". Your program should run and when you press the \"Start New Game\" button, it should produce the output shown at the top of these instructions . If it does not, fix the problem and keep testing until you meet with success.
Solution
//Astroid.java
import java.util.Random;
public class Astroid extends blobzx.PolyBlob {
public Astroid(int x, int y, double r) {
super(-100, -100, r);
this.setDelta(x, y);
// Randomly generate Vertices and Max Radius
Random ran = new Random();
int rad = ran.nextInt(11);
int ver = ran.nextInt(5) + 5;
int[] xArr = new int[ver];
int[] yArr = new int[ver];
double arc = 360/ver;
for(int i = 0; i < ver; i++) {
// Get angle for point
double ang = (arc * i) + (ran.nextDouble() * arc );
// Get radious for angle
double arcRad = (ran.nextInt(rad + 1) + 5);
ang = Math.toRadians(ang);
xArr[i] = (int)Math.round(Math.cos(ang) * arcRad);
yArr[i] = (int)Math.round(Math.sin(ang) * arcRad);
}
this.setPolygon(xArr, yArr);
}
}
=============================================================================
//AsteroidField .java
package asteroidfield;
import blobzx.*;
import java.util.Random;
public class AsteroidField implements BlobGUI {
public static void main(String[] args) {
new AsteroidField();
}
private final SandBox sandBox;
public AsteroidField() {
// Build sandbox
sandBox = new SandBox();
sandBox.setSandBoxMode(SandBoxMode.FLOW);
sandBox.setFrameRate(15);
sandBox.init(this);
}
@Override
public void generate() {
// Randomly generate 20 astroids with random x/y deltas and rot speeds
Random ran = new Random();
for(int i = 0; i < 20; i++) {
int x = (ran.nextInt(3) + 1) * (ran.nextBoolean() ? -1: 1);
int y = (ran.nextInt(3) + 1) * (ran.nextBoolean() ? -1: 1);
double r = ran.nextBoolean() ? -.1: .1;
sandBox.addBlob(new Astroid(x,y,r));
}
}
}
===========================================================================


