Rectangles

Line: Method Line
Medium Difficulty Methods Learning Outcome One Walkthrough
Type: Walkthrough
You should have completed:

Recursion

This topic leads to:

White Box

Summary

In this exercise, you will explore overloaded methods. Several methods will be written that have the same purpose, that of calculating the area of a rectangle, and have the same name, but have different signatures, i.e. they take different parameters.

Task

  1. Create a console application.
  2. Create a method to calculate and return the area of a rectangle that takes two int parameters for length and width. Call the method RectangleArea.
  3. Write code in Main to read two integers from the user and call this method to calculate the area, the program should then display this result.
  4. Check that the calculation is correct.
  5. Write a second RectangleArea method, but this time accept two float parameters for length and width.
  6. Use the debugger to check which method is being called when you run the program.

Questions

  1. Can you change your code to use the second version of RectangleArea with just two letters?
  2. Do you think you have used overloaded methods from the System or other libraries? If so, which?