More Instance Methods

The goal for this exercise is to understand how to create more methods for your class – methods that use instance variables, that accept parameters, and that return values

What you need to do to prepare for this exercise:


Within the provided starter project, there is already a class named More_Methods. You should see the class named Oven below it, in the space indicated. You may need to uncomment the code for this exercise, before you begin working on this exercise. Within the Oven class, you should add an instance variable to keep track of the oven’s current temperature. You also need to add two methods. The first is a ‘setter’ method (aka a ‘mutator’ method) named SetCurrentTemp. This should accept a single parameter (of the appropriate type), which is the temperature that you’d like to set the oven to. There is no value returned. The second is a ‘getter’ method (aka an ‘accessor’ method) named GetCurrentTemp. This should return the current temperature of the oven, and accepts no parameters. Lastly, you should implement the Print method, which takes no parameters, returns no values, and instead just prints out the oven’s current temperature onto the Console, so that the user can see it.

What you need to do for this exercise

You’ll notice that there is a substantial amount of code provided to you in the More_Methods class. Your job (for this exercise) is to just ‘fill in’ the missing parts of the Oven class, as described above, then uncomment everything in the More_Methods class, and make sure that everything compiles and runs just fine.

Also – make sure that you notice what values an Oven object has before you’ve called SetCurrentTemp on it – the provided code makes a point of calling Print before the object has been assigned values (well, before it has been assigned values other than the default values)

What you need to do for this exercise:

  1. Implement the missing methods on the Oven class, as described above.

  2. You should run the sample code that has been provided to you, to confirm that your code is functioning properly. You can do this by this uncommenting, and then running, the code in the RunExercise method of the More_Methods class.