Implementing a Basic Polymorphic Method

 

The goal for this exercise is to make sure that you can write a simple, polymorphic method on your own, from scratch.

 

Let’s say that you’re looking to create some software to model/represent how several different types of lightbulbs work.  For each lightbulb, you’ve got two methods that you’re concerned about:

 

1.    CalculateLight
This takes as it’s only parameter a double value, indicating how much electricity is being supplied to the light bulb, measured in amps (say).  This method will calculate (and return) how bright the light is (measured in candelas).

2.    CalculateHeat
This takes as it’s only parameter a double value, indicating how much electricity is being supplied to the light bulb, measured in amps (say).  This method will calculate how hot the bulb is, measured in degrees Celsius.

 

You’ve also got two types of light bulb:

1.    An incandescent light bulb

2.    A fluorescent light bulb

 

Just to give you some (clearly made-up) formulas to work with, here is what the two methods should return for each of the two light bulb types, assuming that you have a parameter named amps.  Note that these methods should never crash - instead, they should return zero if there are any possible problems.

 

 

CalculateLight

CalculateHeat

Incandescent

Fluorescent

 

 

 

What you need to do for this exercise: 

  1. In the provided starter project, near the Create_Basic_Polymorphic_Method class, you will need to implement three classes:

    1. The base class named LightBulb, which has the two (virtual) methods described above.  The implementations of each of these methods can simply return zero, since you’ll never call them on the base class itself

    2. A subclass named IncandescentLightBulb, which inherits from LightBulb.  You need to implement the CalculateLight and CalculateHeat methods so that given the parameter amps, the methods will return the correct values.

    3. A subclass named FluorescentLightBulb, which inherits from LightBulb.  You need to implement the CalculateLight and CalculateHeat methods so that given the parameter amps, the methods will return the correct values.

  2.  In the provided starter project, in the Create_Basic_Polymorphic_Method.RunExercise() method, you need to create at least one instead of each of the subclasses, and call the CalculateLight and CalculateHeat methods on them.

    a.    You do NOT need to create an instance of the LightBulb base class.