#### Details of this Paper

##### Java Programing Assignment

**Description**

solution

**Question**

Question;Based off of the methods I wrote I need you to create a Class named Projectile and then Create a client to test it. You must incorporate the following criteria.create a class named Projectile with the following private instance;variables;double velocity;double seconds;double angle;double height;double distance;Your class should contain the following public methods;* a three argument constructor that accepts the velocity, seconds, and angle;from the client and places these values into the corresponding instance;variables.;* a set and get method for each instance variable;public double getVel();public double getHeight();public double getSecs();public double getAngle();public double getDistance();private setVel(double v);private setSecs(double s);private setAngle(double a);private setHeight(double h);private setDistance(double d);and two additional methods;double calcDistance();//calculates the distance, stores this into the private instance;//variable distance, and returns this value to the client;double calcHeight();//calculates the height, stores this into the private instance;//variable height, and returns this value to the client;The calcHeight and calcDistance methods should calculate height and;distance according to the formulas from assignment #1 and they should;use the get methods to obtain the values for Velocity, seconds, and angle;where necessary.;You can test your implementation of Projectile by coping and running;TestProjectile.java from the class directory. The command to copy this;file is;cp /home2/classes/csi205/TestProjectile.java TestProjectile.java;Compile and run TestProjectile. This is a client program that will;use and test your Projectile class and methods.;You should submit your Projectile.java file with the following command;turnin-csi205 -c csi205 -p prog2 Projectile.java;Notes;-Include Comments in your code and format your program neatly. Remember to;include your name and Student ID# in your comments. Comment your;variables and provide comments in each of your public methods;-All variables you use for mathematical computations should be of type;double;-The name of the file which you save your application, and hence the class;name, should be named;Projectile.java. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Then for the Client~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ From assignments #1 & #2, we know that we can determine the height and distance;of a projectile based on its initial angle and velocity. We can also calculate the;projectiles X and Y coordinates (it's x and y velocity) based on it's initial;angle and velocity.;The x coordinate is calculated as velocity * cos(angle);The y coordinate is calculated as velocity * sin(angle);Additionally, we can calculate the half-time of flight (the amount of time that;passes from the launch till the projectile is at the top of its trajectory) as;y-coordinate/gravity-constant and the maximum height of the projectile as;y-coordinate * half-time + 0.5 * (gravity-constant * -1) * half-time**2.;Modify your assignment #2 to include the following additional double private data;fields: xcoordinate, ycoordinate, halftime, and maxheight. You should create get;and set methods for these additional fields. Additional methods you should create;for Projectile are;1. calcX - calculate the x coordinate based on the velocity and angle;2. calcY - calculate the y coordinate based on the velocity and angle;3. calcHalf - calculate the half-time based on the y-coordinate and;gravity_constant;4. calcMaxheight - calculate the maximum height based on the y-coordinate;half-time, and gravity_constant;Where needed, these methods should use the get methods to retrieve values from;the private data fields.;You should also create a client/test program that produces the same output as;assignment #2, with the addition of the x and y coordinates, the half time and;the maximum height.;This client should run in a "loop", allowing the user to enter values for angle;velocity and seconds and printing the calculated values for distance, height;x & y coordinates, half time and maximum height until the user enters an angle;of -1 (at which point the program terminates) This client program should be named;TestProjectile.java. The client should use System.out.print/println and nextDouble();to display prompts/output on the screen and to obtain input from the keyboard.;All specifications for assignment #2 remain in effect. Rember to comment both the;Projectile and TestProjectile classes.~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`~~~~~It won't let me attach the code so I'm going to paste my methods here./ This program displays the height and distance of a projectile at a given moment in time based on // take off angle and initial velocity.import java.util.*, public class Projectile { // Initializing my Scanner. public static void main(String[] args) { Scanner console = new Scanner(System.in), System.out.println("This program displays the Height and distance"), System.out.println(" of a projectile at a given moment in time"), System.out.println(" for any given takeoff angle and initial velocity"), // declaring the variable they have to input. System.out.print("Initial Velocity (m/s): "), double velocity = console.nextDouble(), System.out.print("Takeoff angle in degrees: "), double angle = Math.toRadians(console.nextDouble()), System.out.print("Seconds into flight: "), float seconds = console.nextFloat(), double distance = velocity * Math.cos(angle)* seconds, double g = 9.8, / double velocityfactor = velocity * Math.sin(angle)*seconds, double height = -0.5 *g* Math.pow(seconds, 2) + velocityfactor, System.out.println("After " + seconds + " seconds, the projectile is at (in meters) "),System.out.printf (" Height: %.2f \n Distance: %.2f ", height, distance), } }

Paper#37168 | Written in 18-Jul-2015

Price :*$37*