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

android help

pls help

Spaceship.java
public class Spaceship {
    public String shipType;

    public String getShipType() {
      return shipType;
    }

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

1 Answer

Linda de Haan
Linda de Haan
11,221 Points

Please state a question or explain the problem you are facing when you post to the forum. We can't help you if you just write "pls help".

Looking at your code I do see an error. It looks like in the last code block you're trying to set the ShipType to "SHUTTLE". This is how you do it:

    public class Spaceship {
    public String shipType;

    // Set the shipType inside the constructor
    public Spaceship() {
      shipType = "SHUTTLE";
    }

    public String getShipType() {
      return shipType;
    }

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

A constructor doesn't have a return type, so remove the void. Set the ShipType inside the constructor and not inside the parantheses. Also it's best practice to write the constructor at the top of your class, above all your methods and under the member variables.