Android Build an Interactive Story App The Model-View-Presenter Pattern Adding a Custom Constructor

how to set shipType to a specific type of Spaceship in this question?

I've added the second constructor Spaceship(String shipType)

Spaceship.java
public class Spaceship {
    public String shipType;

  Spaceship() 
  {
    shipType="SHUTTLE";
  }

  Spaceship(String shipType)
  {
    this.shipType= new Spaceship();
  }

    public String getShipType() {
      return shipType;
    }

    public void setShipType(String shipType) {
      this.shipType = shipType;
    }
}

1 Answer

Ben Deitch
STAFF
Ben Deitch
Treehouse Teacher

Hi Kumar! Inside the second constructor you're setting 'shipType' equal to a new Spaceship. This doesn't work because 'shipType' requires a String, but it's being set to a Spaceship. Instead you need to use the 'shipType' parameter to update the 'shipType' member variable:

this.shipType = shipType;

Hope that helps!

Thank you! :)