September 12, 2020
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).
This should be a fairly straightforward exercise, that mostly re-enforce what you should know already (except for the UML part, and for how to create a class in Visual Studio).
Draw the UML diagram of this class: it should have two attributes, of type double, and eight methods:
To implement your method in VS, you are given two methods below: you can edit the pre-existing project, or start “fresh”. It is recommended to pick the one you feel the most comfortable with (you will get an opportunity to start “fresh” in the next problem in any case).
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?).ComputePerimeter, Swap, MultiplyRectangle).PreciseRectangle class according to your UML diagram. Don’t forget about the ComputePerimeter, Swap, and MultiplyRectangle methods.Main method, and make sure they behave as expected (can you compute the area, for instance?).This time, you will have to start your project “from scratch” and shouldn’t try to edit a previous program.
.cs files opened and displayed in the Solution Explorer: Program.cs and Circle.cs.Circle.cs, of type double and named radius. Write a set and a get method for this instance variable.Program.cs, write statements that create a new Circle object and set its radius to 2.3. Display its radius at the screen using the method you defined previously.Math.PI is a double holding an approximation of π. In the Main method of Program.cs, write a statement that displays its value at the screen. It should be 3.14159265358979.N, to display the value of π rounded to 3.14.Circle.cs file, add two methods:
Main program, by displaying at the screen the area and the circumference of the object you created at the previous exercise.N to round the circumference.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.
Now that you know more about naming convention, have a look at https://docs.microsoft.com/en-us/dotnet/standard/design-guidelines/naming-guidelines, and particularly at