Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I have to create vectors for a Comet game that is used to break big comets into

ID: 3624399 • Letter: I

Question

I have to create vectors for a Comet game that is used to break big comets into smaller ones.

this is the method the Javadoc, for SmallComet, says we have to make:

explode

public java.util.Vector<Comet> explode()

Since this is the smallest category of comet, it should be completely destroyed if hit. As such, it does not spawn more comets.

Specified by: explode in class Comet

Returns:
An empty vector.




Would this be correct?

public Vector<Comet> explode()
{
return null;
}




if not, or even if it is, how would I go about the larger comets that are to return Vectors of smaller comets. This is what the Javadoc says for a medium sized comet that is supposed to return a vector filled with 3 smaller comets:

explode

public java.util.Vector<Comet> explode()

Splits this comet into pieces.

Specified by: explode in class Comet

Returns:
A vector containing three small comets with the same location as this comet, but randomly chosen velocities

Explanation / Answer

To create an empty Vector, simply instantiate one.

public Vector<Comet> explode()
{
      return new
Vector<Comet>();
}

If you want to return 3 smaller comets:

public Vector<Comet> explode()
{
     
Vector<Comet> output = new Vector<Comet>();

      Comet a, b, c; // 3 smaller commets
      output.add(a);
      output.add(b);
      output.add(c);


      return output;
}