Question
Check what I am missing
Start Page。 a! SpaceShip.java C Source History 6 package spaceshiptest; 9 10 * @author moe222 e public class Spaceship implements Comparable<Spaceship>f 13 14 15 16 17 18 19 201 무 21 曰 enum ShipType { ScoutShip, scienceVessel, construc tionVessel, private ShipType classification; String shipName; String captain; public spaceship (){ this.classification ShipType.Warship; this . shipName Disaster ; this.captainCaptain King of The Fist 23 24L 25 utput
media%2Fff9%2Fff939a07-898a-46fc-956b-95
media%2Fb3c%2Fb3cb36be-6216-4702-a41f-a0
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Note: You missing the parameterized constructor, the modified code is highlighted below Program public class spaceship implem@override public int co mpareTo (SpaceShi p otherShip final int lessThan=-1; final int equalTo0 final int greaterThan-1; if (

Editable code

Program

public class SpaceShip implements Comparable<SpaceShip> {

   

    enum ShipType {ScoutShip,ScienceVessel,ConstructionVessel,Warship,original}

    private ShipType classification;

    String shipName;

    String captain;

     public SpaceShip()

    {

        this.classification=ShipType.Warship;

        this.shipName="Disaster";

        this.captain="Captain King of the Fist";

    }

   

   

    public SpaceShip(ShipType c,String a,String b )

    {

        this.classification=c.Warship;

        this.shipName=a;

        this.captain=b;

    }

   

   public static void main(String[] args) {

      SpaceShip fist=new SpaceShip(ShipType.ScoutShip,"Disaster","Captain fist");

      System.out.println(fist.toString());

      SpaceShip power=new SpaceShip(ShipType.Warship,"Volcana","Captain Power");

      System.out.println(power.toString());

       System.out.println("equals method invoked for object :"+fist.equals(power));

       System.out.println("equals method invoked for object :"+fist.compareTo(power));

   }

     

    @Override

    public int compareTo(SpaceShip otherShip) {

        final int lessThan=-1;

        final int equalTo=0;

        final int greaterThan=1;

        if(this.classification.ordinal()<otherShip.classification.ordinal())

            return lessThan;

         if(this.classification.ordinal()==otherShip.classification.ordinal())

            return equalTo;

          if(this.classification.ordinal()>otherShip.classification.ordinal())

            return greaterThan;

       

           return 0;

     //   throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.

    }

}

Add a comment
Know the answer?
Add Answer to:
Check what I am missing Start Page。 a! SpaceShip.java C Source History 6 package spaceshiptest; 9...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT