You are on page 1of 4

Van Lang University Faculty of Information Technology

PRACTICE 4: CLASS – OBJECT – STATIC –


CONSTRUCTOR – GET - SET
1/ Console application, input data from keyboard:
Open Visual Studio 2019, click Create a new project: select template as the below
image:

Select t”Console App (.Net Framework)”


Naming the solution Week4.sln
2/ Class and object:
Declare class using this syntax:
class ClassName {
//declare properties and method here
// ClassName is the name of the class with Pascal naming convention
}
To create object from class: using the below syntax:
ClassName objName = new ClassName(parameters if needed);

Lecturer: Ms Nguyen Viet Cuong [Type here] Page 1 | 4


Van Lang University Faculty of Information Technology

ClassName is the name of the class with Pascal naming convention


objName is the name of reference variable with Camel naming convention
parameters can be omitted.
a/ Declare class Building with the following properties:
BuildingFloors with int data type
WidthBuilding with float data type
LongBuilding with float data type
Address with data string
FinishedDate with data type DateTime
The following methods:
CalculateTotalArea() return the building area by the expression:
widthBuilding* longBuilding* floors
CalculatePrice(long unitPrice) return the reference price of the buidings by the
expression:
unitPrice* widthBuilding* longBuilding* floors
Students define class Building with the following code:

Code in Mains method of the program:

Lecturer: Ms Nguyen Viet Cuong [Type here] Page 2 | 4


Van Lang University Faculty of Information Technology

Task 1 for students:


If the program prohibit to access properties BuidingFloor but allow to Calculate
Total area, how should you do that.
Task 2 for students:
If the program allows assign value to BuildingFloor from Main method (line 15
above code), but prohibit access its value (line 18 above code), how should you do
that.
(Guide: using constructor and get set method for Task1 and Task2)
3/ Discover static properties and static method:
Students try to understand this code (especially key word static):

Task for students:

Lecturer: Ms Nguyen Viet Cuong [Type here] Page 3 | 4


Van Lang University Faculty of Information Technology

In Mains method of program.cs, write some code to Calculate the area of the circle
with the value of radius entered from the keyboard, pi values and expression of
area calculation accessed from class Circle.
In the code below:

Explain why there are some errors in line 22 and line 24


Lecturer explains carefully the following code to students, especially get set for
properties:

Lecturer: Ms Nguyen Viet Cuong [Type here] Page 4 | 4

You might also like