September 24, 2020
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 attribute.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.You can download an archive with a possible solution to the problem (that also includes a ToString method for the Circle class).
Now, we will create a Room class “from scratch”.
Create a Room class, with three attributes: one to hold the name of the room, one for the length of the room, and one for the width of the room. Name the attributes the way you want, and pick appropriate datatypes, knowing that we want to be able to store the length and the width of the rooms (expressed in meter) using floating point numbers.
Create 6 methods:
To test your Room class, edit your main method to create a Room object and ask the user for its name, length and width, and then display at the screen the name of the Room object that was created.
Now, add two methods:
Test them before moving on.
Suppose that we want to accomodate US users, that are more familiar with feet. Note that we don’t want to change the purpose of our width and length attributes, that are still supposed to hold dimensions in meters, but we want to create methods that perform the conversions for us. Remembering that
add four methods to your class:
Try to write those methods using constant values for the conversion factors, and test them before moving on.
Finally, create a ToString method. To understand the need for such a method, start by trying to display an object “directly”: suppose you have a Room object called myKitchen, add in your main method
Compile and execute your program. Is the information displayed at the screen what you expected? Is it useful?
Add the following to your Room class:
Test this method by adding
to your main method.
Remove .ToString() from the previous statement and compile your program again: did something change?
“Expand” this method by having it return a more meaningfull string: the string returned should also contain the name of the room and its dimensions in meters and feet. Use format specifiers to make it look nice!