For a project I am working on im creating two objects of type CelestialBody. these objects are given values such as name,mass,and id. The issue i am having is when i have to create a getLargestBody(); method, I am not sure on how to compare my two created objects masses. I know how to do this with an array but spec will not allow it. I believe that when called the first object should be both the largest and smallest object then the following objects are compared to what ever one is the largest.
this is the building template for the object
public CelestialBody(String name, double mass, boolean isOrbiting,this){
this.name = name;
this.mass = mass;
this.isOrbiting = isOrbiting;
this.largestBody = largestBody;
totalBodies++;
the get method for largest body
public CelestialBody getLargestBody(){
return largestBody;
}
im just not sure if i need to add an "if" statement within my get method or how to compare the masses of the objects

New Topic/Question
Reply



MultiQuote



|