Hi there. Complete beginner on Java and OO principles. Having a little trouble in trying to figure out how to make objects move across the screen. Eventually, this will be a model of the solar system.
So I have a planetObject class that represents a planet in the solar system:
public class PlanetObject {
private double distance;
private double angle;
private double diameter;
private String colour;
private double speed;
public double getDistance(){
return distance;
}
public double getAngle(){
return angle;
}
public double getDiameter(){
return diameter;
}
public String getColour(){
return colour;
}
public double getSpeed(){
return speed;
}
public double move(){
angle += speed;
return angle;
}
public PlanetObject(double distance, double angle, double diameter, String colour, double speed){
this.distance = distance;
this.angle = angle;
this.diameter = diameter;
this.colour = colour;
this.speed = speed;
}
}
And a solarModel class - think of this as a driver
public class SolarModel {
public static void main(String[] args){
SolarSystem model = new SolarSystem(700, 700);
/* Start the game loop. Invoke each object to the screen */
for(int i = 10; i <= 4000; i++){
/* Draw the sun */
SunObject sun = new SunObject(30, 50, 50, "YELLOW", 0);
model.drawSolarObject(sun.getDistance(), sun.getAngle(), sun.getDiameter(), sun.getColour());
/*Draw the earth */
PlanetObject earth = new PlanetObject(100, 30, 15, "GREEN", 10);
model.drawSolarObject(earth.getDistance(), earth.getAngle(), earth.getDiameter(), earth.getColour());
earth.move();
model.finishedDrawing();
}
}
}
Now, the class SolarSystem is supplied already, I am just invoking it and using the drawSolarObject() method by passing in the values.
My problem is, I cannot get the earth to rotate around the sun. Help would be much appreciated, thanks.