import java.awt.*;
import java.awt.event.*;
import java.util.Scanner;
class Graph_mod extends Frame {
public static void main( String[] args ) {
Scanner input = new Scanner(System.in);
System.out.println("enter v :");
double v = input.nextDouble();
System.out.println("enter a :");
double a1 = input.nextDouble();
double a2 = a1*Math.PI/180;
double t = v*Math.sin(a2)/9.8;
double h = Math.pow(v*Math.sin(a2), 2)/(2*9.8);
I want to use this variable(h, r)
double r = Math.pow(v,2)*Math.sin(2*a2)/9.8;
System.out.println("t is" + t );
System.out.println("h is" + h );
System.out.println("r is " + r );
new Graph_mod( "graph");
}
@Override
public void paint( Graphics g )
{
g.setColor( new Color( 0x000000 ) );
g.drawLine( 0, 300, 600, 300 );
g.drawLine( 300, 0, 300, 600 );
for( int i = 0; i < 6; i++ )
{
g.drawLine( i*100 , 298 , i*100, 302 );
g.drawLine( 298, i*100, 302, i*100 );
}
g.setColor( new Color( 0xFF0000 ) );
int px=-1;
int py=300;
int x, y;
for( x = 0; x < 600; x++ )
{
y = My_function( x );
g.drawLine( px, py,x, y );
px = x;
py = y;
}
}
private int My_function( int inX )
{
double x, y;
int outY;
x = (inX - 300.)/ 100.;
In here
y = (-4*h/Math.pow(r,2) * x * x) + (4*h/r*x);
outY = (int)( y * -100. + 300. );
return outY;
}
public Graph_mod( String title )
{
super( title );
addWindowListener( new WindowAdapter(){
public void windowClosing( WindowEvent we ){
System.exit( 0 );
}
} );
setBounds( 0, 0, 600, 600 );
setVisible( true );
}
}
I want to make a parabola movement calculator code, but in the process that making a graph, I had some problem. I imported scanner and used in main method, but I can't use it in another method(My_funtion). I know it's get better when I use parameter, but it's too difficult to me... please help