Rectangles
Line: |
Method Line |
|
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
- Create a console application.
- 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.
- 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.
- Check that the calculation is correct.
- Write a second RectangleArea method, but this time accept two float parameters for length and width.
- Use the debugger to check which method is being called when you run the program.
Questions
- Can you change your code to use the second version of RectangleArea with just two letters?
- Do you think you have used overloaded methods from the System or other libraries? If so, which?