Android Build an Interactive Story App The Model-View-Presenter Pattern Creating a Data Model

Dominic Sayers
Dominic Sayers
2,479 Points

Finally, add the setter method What am I doing wrong?

It also says there the previous one is invalid but I didn't change anything in the previous answer

Spaceship.java
public class Spaceship{
    public String shipType; 

  public String getType(){
     return shipType; 
  }

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

2 Answers

Jennifer Nordell
STAFF
Jennifer Nordell
Treehouse Staff

Hi there! You're doing great, but it has a bit of a problem with your naming conventions here. It wants getShipType and setShipType. It is a spaceship, after all. It could also have properties of weaponType, engineType, crewType, missionType etc. So getType and setType might not be as descriptive as you think it is.

Hope this helps! :sparkles:

Dominic Sayers
Dominic Sayers
2,479 Points

That worked thank you! just curious why getShipType and not getshipType after-all its returning shipType and not Shiptype?

Jennifer Nordell
Jennifer Nordell
Treehouse Staff

Because that's standard for camel-case. Every individual word is capitalized. That being said, if you had a compound word, you wouldn't need to break that up. For example you would write: getBaseball instead of getBaseBall as "baseball" is one word. The exception to this is when we make classes which are what we call upper camel-case. They begin with a capital letter. Hope this helps! :sparkles:

mongst
mongst
10,423 Points

Yes! As Jennifer Nordell Said your code should look like this:

public class Spaceship{
    public String shipType; 

  public String getShipType(){
     return shipType; 
  }

  public void setShipType(String type){
     shipType = type; 
  }
}
Dominic Sayers
Dominic Sayers
2,479 Points

That makes sense Thank you again!