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 (Retired) The Model-View-Controller Pattern Adding a Custom Constructor

Adding the second constructor.

Not able to cross this second challenge. Here is my code:

Spaceship.java
public class Spaceship {
    public String mType= "SHUTTLE";
    public String type;

    public String getType() {
      return mType;
    }

    public void setType(String type) {
      mType = type;
    }
}

3 Answers

Ken Alger
STAFF
Ken Alger
Treehouse Teacher

I answered this in your other post on this same challenge.

Hey Ken,

Thank you for your detailed explanation below for the second part of the challenge. It helps clear some of the fog. Still not really wrapping my head around it yet but I keep getting bits and pieces.

Again, thank you! Joel

Michael McKenna
Michael McKenna
3,451 Points

I read Ken's explanation and I still can't get it either. Has anyone else been able to do this?

Ken Alger
Ken Alger
Treehouse Teacher

Michael;

Let's take a look at this:

Task 1

Our first constructor sets a default type of Spaceship as "SHUTTLE", our code then looks like:

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

Now when you call Spaceship() in your code it will default to the type of SHUTTLE.

Task 2

The second task (constructor) needs to be able to take a different type for the spaceship, a constructor that will set the type to the type that is passed in.

public Spaceship(String type) {
    mType = type;
}

Now if we can create Spaceships and call them anything other than SHUTTLE.

Does that make any sense?

Ken

Michael McKenna
Michael McKenna
3,451 Points

Yes, thank you very much. I appreciate you taking your time for your swift and thorough explanations.

Ken Alger
Ken Alger
Treehouse Teacher

Michael;

No problem at all. Welcome to Treehouse and Happy Holidays.

Ken