This site requires JavaScript, please enable it in your browser!
Greenfoot back
Toodumbtocode
Toodumbtocode wrote ...

2018/11/5

NEED HELP WITH NEWTON PROJECT

Toodumbtocode Toodumbtocode

2018/11/5

#
on page 91 of the greenfoot book it says I need to import the list class but it isn't working. what am I doing wrong????????????
private static final double GRAVITY = 5.8;
    private static final Color defaultColor = new Color(255, 216, 0);
     
    // fields
    private double mass;
    import java.util.List;
    
    /**
     * Construct a Body with default size, mass, movement and color.
     */
    public Body()
    {
        this (20, 300, new Vector(0, 1.0), defaultColor);
    }
    
    /**
     * Construct a Body with a specified size, mass, movement and color.
     */
    public Body(int size, double mass, Vector movement, Color color)
    {
        mass = mass;
        addForce(movement);
        GreenfootImage image = new GreenfootImage (size, size);
        image.setColor (color);
        image.fillOval (0, 0, size-1, size-1);
        setImage (image);
    }
    
    /**
     * Act. That is: apply  the gravitation forces from
     * all other bodies around, and then move.
     */
    public void act() 
    {
        applyForces();
        move();
        // To be done - not yet implemented
    }
    
    /**
     * Return the mass of this body.
     */
    public double getMass()
    {
        return mass;
    }
     private void applyForces()
     {
         {
         List<Body> bodies = getWorld().getObjects(Body.class);
         for (Body body : bodies)
         {
         if (body != this)
         {
         applyGravity (body);
         }
         }
        }

    }
    private void applyGravity(Body other)
    {
    }
}
danpost danpost

2018/11/5

#
Import statements must be provided before the class code (starting at line 1 in your class editor, in your case).
You need to login to post a reply.