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 trialMUZ140118 Cathrine Makuya
10,300 Pointsl need help on the task 1
The LandingActivity interacts with the Spaceship model object we created. Start by setting mSpaceship to a new Spaceship object in the onCreate() method. Use the custom constructor that takes a String parameter, and pass in "FIREFLY" as the parameter
4 Answers
haunguyen
14,985 PointsJust 1 line of code
mSpaceship = new Spaceship("FIREFLY");
The Spaceship class has 2 constructors, 1 is just a default constructor that does not take any parameter. The other one takes a string parameter.
When you call new Spaceship("FIREFLY");
you call the second constructor and passed in the string.
Patrick Munemo
14,892 Pointsspaceship = new Spaceship("FIREFLY");
SIBONGILE CHIROPA
4,909 Pointspublic class Spaceship { private String mType; private int mNumPassengers = 0;
public String getType() {
return mType;
}
public void setType(String type) {
mType = type;
}
public int getNumPassengers() {
return mNumPassengers;
}
public void setNumPassengers(int numPassengers) {
mNumPassengers = numPassengers;
}
public Spaceship() {
mType = "SHUTTLE";
}
public Spaceship(String type) {
mType = type;
mSpaceship = new Spaceship("FIREFLY");
}
} am getting an error where am i wrong
Ken Wagner
7,298 PointsSIBONGILE CHIROPA, you have chosen the wrong file.
It goes in the file named: LandingActivity.java
TERRENCE MAVHUNGA
6,053 PointsOn this file : LandingActivity.java
//add this code mSpaceship = new Spaceship("FIREFLY");