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);
我想使用这个变量(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.;
在这里
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 );
}
}
我想制作抛物线运动计算器代码,但在制作图表的过程中,我遇到了一些问题。我导入了扫描仪并在主要方法中使用,但我不能在其他方法(My_funtion)中使用它。我知道当我使用参数时它会变得更好,但这对我来说太难了......请帮助