Maturaarbeit 2.0
This is the first class I added to my Maturaarbeit 2.0, I think it helps quite much to have one Object for all the Bodies. (see my Maturaarbeit 1.0 what I mean, a lot of variables and other things but for every body the same)
I realise how bad my “Maturaarbeit” was back then^^
public class Planet {
private final double gravitationConstant = 6.67428*Math.pow(10, -11); // N(m/kg)²
private double weight;
private double speed;
private double x_Coordinate;
private double y_Coordinate;
public double acceleration(){ return 0; }
public void nextPosition(){}
public void gravitationForce(){}
// Getter
public double getX_Coordinate(){ return x_Coordinate; }
public double getY_Coordinate(){ return y_Coordinate; }
public double getWeight(){ return weight; }
public double getSpeed(){ return speed; }
// Setter
public void setX_Coordinate(){}
public void setY_Coordinate(){}
public void setSpeed(){}
}
I'll keep you up to date, but I'll need a lot of time^^
Just some inputs:
gravitationConstant could be static. It’s the same for all instances.
Where has the constructor gone? Or how do you set e.g. the weight?
Wouldn’t mass be a better name than weight?
You could use an extra point (or vector) object instead of just two coords (look at java.awt.Point). This would give you the possibility to simply add some methods for translations, vector operations or even a third dimension. Getting the X coord could look like this: planet.getPosition().getX();
I think velocity is more occurate than speed.
Velocity (for you Speed^^) is a vector quantity and should be represented as such (as I said, an extra vector object would be great [the body _has a_ velocity]).
Last but not least: What about the sun (or the moon)? I think an object called Body or the like would do a better job. The sun _is a_ Body with velocity 0, but never a Planet! You even said it by yourself: “have one Object for all the Bodies”!
Think again about your class design… it’s a hard job!
jop thx for the inputs, im my current version the vectorstuff and the missing constructor is allready implemented.
Yeah class design is the hardest part of a programm^^ especially responsibility-driven design