Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

can someone help fix my code where it compiles? import java.awt.Color; import ja

ID: 3531035 • Letter: C

Question

can someone help fix my code where it compiles?


import java.awt.Color;

import java.awt.Graphics;

import java.util.Scanner;


/**

*

* @author Owner

*/

public class S3g {





// constant for Earth acceleration in meters/second^2

public static final double ACCELERATION = -9.81;


public static void main(String[] args) {

Scanner console = new Scanner(System.in);



System.out.println("This program computes the");

System.out.println("trajectory of a projectile given");

System.out.println("its initial velocity and its");

System.out.println("angle relative to the");

System.out.println("horizontal.");

System.out.println();


System.out.print("velocity (meters/second)? ");

double velocity = console.nextDouble();

System.out.print("angle (degrees)? ");

double angle = Math.toRadians(console.nextDouble());

System.out.print("number of steps to display? ");

int steps = console.nextInt();

System.out.println();

//create the drawing panel

DrawingPanel p = new DrawingPanel(420, 220);

// set the background to cyan

p.setBackground(Color.cyan);

// get a graphics object for the drawing panel

Graphics g = p.getGraphics();

double xVelocity = velocity * Math.cos(angle);

double yVelocity = velocity * Math.sin(angle);

double totalTime = - 2.0 * yVelocity / ACCELERATION;

double timeIncrement = totalTime / steps;

double xIncrement = xVelocity * timeIncrement;

// some numbers for the drawingpanel

// come up with a even distribution of points for the plot

// 10 pixels are left for edge padding

int xDrawSteps = 410/(steps);

// come up with the maximum value for y

double maxYTime = -1.0 * yVelocity /ACCELERATION;

double maxY = yVelocity * maxYTime + 0.5 * ACCELERATION * maxYTime * maxYTime;

// work out the proportion between height and the number of pixels

// available on the y axis 10 pixels are left for padding

double yScale = 210/maxY;


double x = 0.0;

double y = 0.0;

double t = 0.0;

int xStep = 5;

System.out.println("step x y time");

System.out.println("0 0.0 0.0 0.0");

//draw the first dot at a nominal zero point (5,215)

g.fillOval(xStep,215,5,5);

for (int i = 1; i <= steps; i++) {

t += timeIncrement;

x += xIncrement;

// increment the x coordinate for the graph

xStep += xDrawSteps;

y = yVelocity * t + 0.5 * ACCELERATION * t * t;

System.out.println(i + " " + round2(x) + " " +

round2(y) + " " + round2(t));

// draw a scaled point on the graph

g.fillOval(xStep,(215-((int)(y*yScale))),5,5);

}

}

}

Explanation / Answer

It's because it cannot find your DrawingPanel.java file. below is such a file:


http://www.buildingjavaprograms.com/DrawingPanel.java

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote