赢得';不能在java中工作-我需要修复什么?

赢得';不能在java中工作-我需要修复什么?,java,eclipse,error-handling,physics,multiplication,Java,Eclipse,Error Handling,Physics,Multiplication,我在Eclipse中编写这段代码是为了求解NBody物理方程,但是有一个未解决的错误。在这一行“double Fnet=Gmassmass/(distdistdist);”中,eclipse在Gmass下面加上红色下划线,并给出消息“参数类型double,double[]的运算符*未定义”。如何解决此问题?完整代码包含在下面 public class NBody { public static final String PLANETS_FILE = "planets.txt";

我在Eclipse中编写这段代码是为了求解NBody物理方程,但是有一个未解决的错误。在这一行“double Fnet=Gmassmass/(distdistdist);”中,eclipse在Gmass下面加上红色下划线,并给出消息“参数类型double,double[]的运算符*未定义”。如何解决此问题?完整代码包含在下面

public class NBody {

    public static final String PLANETS_FILE = "planets.txt";

    // animation pause (in miliseconds)
    public static final int DELAY = 20;

    // music (2001 theme)
    public static final String MUSIC = "2001theme.wav";

    // background image
    public static final String BACKGROUND = "starfield.jpg";

    // gravitational constant (N m^2 / kg^2)
    public static final double G = 6.67e-11;

                                        // parameters from command line
    public static double T;             // simulate from time 0 to T (s)
    public static double dt;            // time quantum (s)

                                        // parameters from first two lines 
    public static int N;                // number of bodies
    public static double R;             // radius of universe

    public static double[] rx;          // x position (m)
    public static double[] ry;          // y position (m)
    public static double[] vx;          // x velocity (m/s)
    public static double[] vy;          // y velocity (m/s)
    public static double[] mass;        // mass (kg)
    public static String[] image;       // name of gif

    // TODO: read the planet file, new the parallel arrays, and load
    // their values from the file.
    public static void loadPlanets(String planetFileName) {
        java.util.Scanner input = new java.util.Scanner(System.in);

            int N = input.nextInt();
            double R = input.nextDouble();
            double[] rx = new double[N];          
            double[] ry = new double[N];         
            double[] vx = new double[N];          
            double[] vy = new double[N];          
            double[] mass = new double[N];        
            String[] image= new String[N];

            for (int i = 0; i < N; i++) {

                    rx[i] = input.nextDouble();
                    ry[i] = input.nextDouble(); 
                    vx[i] = input.nextDouble();
                    vy[i] = input.nextDouble(); 
                    mass[i] = input.nextDouble(); 
                    image[i] = "./images/" + input.next();
                }  

        } 




    public static void runSimulation() {

        // run numerical simulation from 0 to T
        for (double t = 0.0; t < T; t += dt) {

            // the x- and y-components of force
            double[] fx = new double[N];
            double[] fy = new double[N];

            // calculate forces on each object
            for (int i = 0; i < N; i++) {

                // reset forces to zero 
                fx[i] = 0.0;
                fy[i] = 0.0;

                for (int j = 0; j < N; j++) {
                    if (i != j) {
                        double dx = rx[j] - rx[i]; 
                        double dy = ry[j] - ry[i]; 
                        double dist = Math.sqrt(dx*dx + dy*dy);
                        double Fnet = G*mass*mass/(dist*dist);

                        fx[i] += Fnet * dx / dist;
                        fy[i] += Fnet * dy / dist; 
                    }
                } 
            }

            //calculate acceleration, velocities and positions
            double ax = 0.0;
            double ay = 0.0;
            for (int i = 0; i < N; i++) {
                ax = fx[i] / mass[i];
                ay = fy[i] / mass[i];

                vx[i] += dt * ax;
                vy[i] += dt * ay;

                rx[i] += dt * vx[i];
                ry[i] += dt * vy[i];



            // draw background and then planets
            StdDraw.picture(0, 0, BACKGROUND);
            StdDraw.picture(rx[i], ry[i], image[i]); 

            //loop to plot the N bodies

            // pause for a short while, using "animation mode"
            StdDraw.show(DELAY);
            }
        }

    }

    public static void main(String[] args) {

        // TODO: read T and dt from command line.
        T = 0;

        // load planets from file specified in the command line
        String planetFileName = "planets.txt";
        loadPlanets(planetFileName);

        // rescale coordinates that we can use natural x- and y-coordinates
        StdDraw.setXscale(-R, +R);
        StdDraw.setYscale(-R, +R);

        StdAudio.play( MUSIC );

        // turn on animation mode
        StdDraw.show(0);

        // Run simulation
        runSimulation();

        // print final state of universe to standard output
        System.out.printf("%d\n", N);
        System.out.printf("%.2e\n", R);
        for (int i = 0; i < N; i++) {
            System.out.printf("%11.4e %11.4e %11.4e %11.4e %11.4e %12s\n",
                          rx[i], ry[i], vx[i], vy[i], mass[i], image[i]);
        }

    }
}
公共类NBody{
公共静态最终字符串planers\u FILE=“planers.txt”;
//动画暂停(以毫秒为单位)
公共静态最终整数延迟=20;
//音乐(2001年主题)
公共静态最终弦乐=“2001theme.wav”;
//背景图像
公共静态最终字符串BACKGROUND=“starfield.jpg”;
//重力常数(N m^2/kg^2)
公共静态最终双G=6.67e-11;
//来自命令行的参数
public static double T;//从时间0模拟到时间T(s)
公共静态双dt;//时间量
//前两行的参数
public static int N;//实体数
公共静态双R;//宇宙半径
公共静态双[]rx;//x位置(m)
公共静态双[]ry;//y位置(m)
公共静态双[]vx;//x速度(m/s)
公共静态双[]vy;//y速度(m/s)
公共静态双[]质量;//质量(kg)
公共静态字符串[]image;//gif的名称
//TODO:读取planet文件,新建并行阵列,然后加载
//从文件中删除它们的值。
公共静态void loadPlanets(字符串planetFileName){
java.util.Scanner输入=新的java.util.Scanner(System.in);
int N=input.nextInt();
double R=input.nextDouble();
双精度[]rx=新双精度[N];
双精度[]ry=新双精度[N];
双精度[]vx=新双精度[N];
双精度[]vy=新双精度[N];
双[]质量=新双[N];
字符串[]图像=新字符串[N];
对于(int i=0;i
您确实尝试过这样做:

double
*
double[]
*
double[]
/(
double
*
double


这显然(我希望这是显而易见的)不起作用。

G
是一个
质量
是一个数组。你不能做
G*mass