Get immediate access to this and 4,000+ other videos and books.

Take your career further with a raywenderlich.com Pro subscription. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it’s simply the best investment you can make in your development career.

Build the Model Pro

The parameters of the Creature constructor should be var to prevent the “Cannot find setter for field error.”

Create the Model layer for the course sample project, including adding JUnit tests of Model layer classes.

Contributors

Heads up... You've reached locked video content where the transcript will be shown as obfuscated text.

You can unlock the rest of this video course, and our entire catalogue of books and videos, with a raywenderlich.com Professional subscription.

I have the starter project for the course open up here in Android Studio 3.1.4.

data class Creature(
    val attributes: CreatureAttributes = CreatureAttributes(),
    val hitPoints: Int = 0,
    val name: String,
    val drawable: Int = 0
)
class CreatureGeneratorTest {

}
   private lateinit var creatureGenerator: CreatureGenerator
   @Before
  fun setup() {
    creatureGenerator = CreatureGenerator()
  }
class CreatureGenerator
   @Test
  fun testGenerateHitPoints() {
    val attributes = CreatureAttributes(
        intelligence = 7,
        strength = 3,
        endurance = 10
    )
    val name = "Rikachu"
     val expectedCreature = Creature(attributes, 84, name)
   }
 assertEquals(expectedCreature, creatureGenerator.generateCreature(attributes, name))

class CreatureGenerator {
    
   fun generateCreature(attributes: CreatureAttributes, name: String = "", drawable: Int = 0): Creature {
     return Creature()
  }
}
    val hitPoints = 5 * attributes.intelligence +
        3 * attributes.strength +
        4 * attributes.endurance
    return Creature(attributes, hitPoints, name, drawable)

Reviews

Comments