I'm having problems trying to come up with a Boolean method in my Planet class to remove an array by name and shift values to close any null gaps. Could any one assist with that? Below are my classes for the Moon and Planet...
MOON CLASS:-
public class Moon
{
private float angle=0.01;
// add class member variables here
private String name;
private float radius;
private float distance;
private float speed;
private int orbitalPeriod;
// add constructor here
public Moon(String name, float radius, float distance, float speed, int orbitalPeriod)
{
this.name=name;
this.radius=radius;
this.distance=distance;
this.speed=speed;
this.orbitalPeriod=orbitalPeriod;
}
// add other methods here
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public float getRadius()
{
return radius;
}
public float getDistance()
{
return distance;
}
public float getSpeed()
{
return speed;
}
public float getAngle()
{
return angle;
}
public int getOrbitalPeriod()
{
return orbitalPeriod;
}
public void setOrbitalPeriod(int orbitalPeriod)
{
this.orbitalPeriod = orbitalPeriod;
}
public String toString()
{
return "Moon:"+name+" - (orbit= "+orbitalPeriod+")";
}
// This will display the moon when other code is completed.
public void display()
{
angle=angle+(0.01*speed);
pushMatrix();
rotate(angle);
translate(distance, 0);
fill(149, 149, 149);
ellipse(0, 0, radius*2, radius*2);
popMatrix();
}
}
PLANET CLASS:-
public class Planet
{
private float angle=0.01;
// add class member variables here
private float radius, distance, speed;
private String name;
private Moon [] moons = new Moon [5];
private int numOfMoons = 0;
// add constructor here
public Planet(String name, float radius, float distance, float speed)
{
this.name=name;
this.radius=radius;
this.distance=distance;
this.speed=speed;
}
// add other methods here
public String getName()
{
return name;
}
public float getRadius()
{
return radius;
}
public void setRadius(float radius)
{
this.radius = radius;
}
public float getDistance()
{
return distance;
}
public float getSpeed()
{
return speed;
}
public Moon[] getMoons()
{
return moons;
}
public String toString()
{
return "Planet:"+name+" (r= "+radius+ "d= "+distance+") has "+moons.length+" moon(s)";
}
public void printMoons()
{
for (Moon moon : getMoons())
println(moon);
}
public void addMoon(Moon moon)
{
moons[numOfMoons] = moon;
++numOfMoons;
}
public boolean removeMoonByName(String moonName)
{
for (Moon moon : getMoons())
if(moon!=null)
moon.removeMoonByName();
}
// This will display the moon when other code is completed. You don't need to understand this code.
public void display()
{
angle=angle+(0.01*speed);
pushMatrix();
rotate(angle);
translate(distance, 0);
fill(255, 255, 255);
ellipse(0, 0, radius*2, radius*2);
for (Moon moon : getMoons())
if(moon!=null)
moon.display();
popMatrix();
}
}