February 1, 2018
Deadlines: This lab needs to be completed before taking Lab 10, and is critical to complete Project #2.
Dependencies: Part I is about finishing Lab 8, and it is recommended that you complete this part before starting Part II.
If time allows, I’ll grade your quiz and make personal feedback during the lab. If not, you’ll have it back next Tuesday, and are encouraged to meet with me if something isn’t clear.
Go back to Lab 8 and make sure you properly “enriched” Rectangle.cs
. Are the headers correct, i.e., those studied in class? Make sure you implemented them correctly, and test them. Once you completed that, implement the MultiplyRectangle
method we saw in class, whose header is public void MultiplyRectangle(int factor)
.
In this exercise, you will create your own first class instead of using and expanding one that was written for you. The idea is to take inspiration from the class you already know (Rectangle
) to create a new class, called PreciseRectangle
, that will manipulate rectangles whose width and length are floating-point values, instead of integers (as in Rectangle
).
Draw the UML diagram of this class: it should have two attributes, of type double
, and five methods: two setters, two getters (i.e., one for each attribute), and one method to compute the area of a precise rectangle.
To implement your method in VS, I explain two methods below: you can edit the pre-existing project, or start “fresh”. I recommend that you pick the one you feel the most comfortable with, and then try the other one.
Rectangle
project, extract it in a folder, open it with VS.class Rectangle
with class PreciseRectangle
.Main
method in “Program.cs”.PreciseRectangle.cs
to now store the width
and the length
with double
, and to propagate this change accordingly. What should be the return type of GetWidth
, for instance?Main
method, and make sure they behave as expected (can you compute the area, for instance?)..cs
files opened and displayed in the Solution Explorer: “Program.cs” and “PreciseRectangle.cs”.PreciseRectangle
class according to your UML diagram.Main
method, and make sure they behave as expected (can you compute the area, for instance?).The following are two independent tasks, to widen your understanding of this class, and to prepare you for the next labs.
Class diagram (the one we will be using) are just a special case of UML diagram. Have a look at https://en.wikipedia.org/wiki/Unified_Modeling_Language#Diagrams: in which category are class diagram, behaviour, or structure diagram? Have a look at https://en.wikipedia.org/wiki/Activity_diagram and try to read the example of activity diagram for a guided brainstorming process.