Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Build an Interactive Story App Finishing the User Interface Using a Model in the Presenter

Caleb Seeling
Caleb Seeling
1,189 Points

I still can't get to solve this question.

I asked already before how to solve this and I got a clue from a user but I still can't solve it.

LandingActivity.java
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class LandingActivity extends AppCompatActivity {

    public Button thrustButton;
    public TextView typeLabel;
    public EditText passengersField;

    public Spaceship spaceship;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_landing);

        thrustButton = (Button)findViewById(R.id.thrustButton);
        typeLabel = (TextView)findViewById(R.id.typeTextView);
        passengersField = (EditText)findViewById(R.id.passengersEditText);



    }
}
Spaceship.java
public class Spaceship {
    private String shipType;
    private int numPassengers = 0;

    public String getShipType() {
      return shipType;
    }

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

    public int getNumPassengers() {
      return numPassengers;
    }

    public void setNumPassengers(int numPassengers) {
      this.numPassengers = numPassengers;
    }

    public Spaceship() {
      shipType = "SHUTTLE";
    }

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

1 Answer

Hi Caleb,

The first task wants you to set the existing spaceship variable to be a new instance of Spaceship. The question wants us to pass the value "FIREFLY" into that new instance.

So, where the challenge says "add you code here" start with the existing variable name, then put an equals sign. That means we're going to assign something into the variable. We want to assign a new spaceship, so type that, new Spaceship and pass in the string that the challenge says, "FIREFLY".

That all looks like:

spaceship = new Spaceship("FIREFLY");

What we're doing here is calling the constructor of the Spaceship class (it has 2 but let's not worry about that!). The constructor constructs a new Spaceship and calls that ship whatever name you pass in. So, now you have a shiny new FIREFLY type spaceship ready to do whatever the next task wants you to do!

Let me know how you get on.

Steve.