EXERCISE 1:
❑Create a class "House", with an attribute “length”,
“width”, "area", a constructor that sets the attributes, and
a method "ShowData" to display "I am a house, my area
is xxx m2 (instead of xxx, it will show the real surface).
❑Write a second class to test your House class: TestClass.
▪The second class should allow the user to input length and width
of the house.
▪Display the area of the house using ShowData method.
11/12/2024 ANDARGACHEW A. 44
EXERCISE 2:
❑Create a class “Person", with an attribute “name” and
“age”, a constructor that sets the attributes, and a
method “PrintData" to display “Name: xxxx and Age:
xxxx. (instead of xxxx, it will show the real name and
age).
❑Write a second class to test your Person class: TestClass.
▪Create two instances of the "Person" class, set their attributes
using the constructor.
▪Print persons’ name and age using PrintData method.
11/12/2024 ANDARGACHEW A. 45
EXERCISE 3:
❑Write a C# program that accept two integers and return
true if either one is 5 or their sum or difference is 5.
▪Class names: Program3, TestProgram3(Main method)
▪Attributes: number1 and number2
▪Method: checkIf5
▪Sample Output:
Enter the first number: 5
Enter the second number: 3
True
Enter the first number: 3
Enter the second number: 4
False
11/12/2024 ANDARGACHEW A. 46
EXERCISE 4:
❑Create a class called ‘Circle’, which contains the following:
▪Two private instance variables: radius (of the type double) and color
(of the type String), with default value of 1.0 and "red", respectively
(use the constructors to set the values).
▪Two overloaded constructors - a default constructor with no argument,
and a constructor which takes a double argument for radius.
▪Two public methods: getPerimeter() and getArea(), which return the
perimeter(2πr) and area(πr2) of this instance, respectively.
❑Write a test class called TestCircle which demonstrate the
Circle class.
11/12/2024 ANDARGACHEW A. 47
EXERCISE 5:
❑Write a C# program to check if it is possible to add two integers to
get the third integer from three given integers
▪Class names: Program5, TestProgram5(Main method)
▪Attributes: number1 , number2 and number3
▪Method: checkIfPossible
▪Sample Output:
Enter the first number: 5
Enter the second number: 3
Enter the third number: 2
True
Enter the first number: 3
Enter the second number: 4
Enter the third number: 5
False
11/12/2024 ANDARGACHEW A. 48
EXERCISE 6:
❑Write a C# program to check if two or more non-negative given
integers have the same rightmost digit.
▪Class names: Program6 , TestProgram6(Main method)
▪Attributes: number1 , number2 and number3
▪Method: checkRigtmostDigit
▪Sample Output:
Enter the first number: 50
Enter the second number: 30
Enter the third number: 20
True
Enter the first number: 31
Enter the second number: 43
Enter the third number: 52
False
11/12/2024 ANDARGACHEW A. 49
EXERCISE 7:
❑Write a C# program to calculate the area of the rectangle.
▪Class names: Program7 , TestProgram7(Main method)
▪Attributes: length, width
▪Method: caculateArea, getLength, getWidth, setLength, setWidth
▪Sample Output:
Enter the length of the rectangle: 6
Enter the width of the rectangle: 7
******************************
The length of the rectangle is: 6
The width of the rectangle is: 7
The area of the rectangle is: 42
11/12/2024 ANDARGACHEW A. 50
EXERCISE 8:
❑Write a C# program to check which number nearest to
the value 100 among two given integers. Return 0 if the
two numbers are equal.
▪Class names: Program8 , TestProgram8(Main method)
▪Attributes: number1, number2
▪Method: checkNearest
▪Sample Output:
Enter the first number: 89
Enter the second number: 92
92
11/12/2024 ANDARGACHEW A. 51