You are on page 1of 3

Practical

Programming in C# Page 1 of 3
1. Create an interface Icar that has the following methods:
- Method “calculateTax()”, returns the type float: calculate the tax of the car.
- Method “calculatePrice()”, returns the type float: calculate the total cost of the
car.
- Method “getInfor()”, returns the type void: display the information of the car.

2. Create a class Car inherit from interface Icar.

[6]
Declare fields has access modifier as private use for properties: name,
producer, year, seat and rootprice.

This class has the following public properties :

Property name Data type Description Constraint


Name string Name the car length from 0 to 40
characters
Producer string name of length from 0 to 40
manufacturer characters
Year int production year Value must be
greater than in
1900
Seat int Number of seats Value from 0 to 200
RootPrice float Price original Value must be
greater than in 0

- Implement method calculateTax() to calculate the Tax as follows:


o If the car has under 7 seats then tax = RootPrice * 60%.
o Else tax = RootPrice * 70%

- Implement method calculatePrice() to calculate TotalPrice as follows:


o TotalPrice=RootPrice + Tax

- Implement method getInfor() to show the information as follows: .... car


produced by ... in ... has ... seats with the total price is ....$. Variable includes
:name of the car, the name of the manufacturer, year of production, seats and
TotalPrice (For example: Ford car produced by Ford in 1997 has 4 seats with
the total price is 20000 $).
3. Declaring class LuxuryCar inherits from class Car :
4. This class has the following public field :

Property name Data type Description


specialRate Float The rate of charge
consumption special.
Default value is 80%

- Override method calculatePrice to calculate TotalPrice as follows :

TotalPrice = RootPrice + Tax + RootPrice * specialRate

- Overload method calculatePrice with 1 parameter named “transportCost” with


type float. It calculates TotalCost as follows:

Programming in C# Page 2 of 3
TotalPrice = RootPrice + Tax + RootPrice * specialRate +
transportCost.

5. Create a class named Test.


- Declare and initialize 1 instance named “myLuxuryCar” of class LuxuryCar.
o Input Name, Producer, Year, Seat, rootPrice from the keyboard (Catch
exception when input value). Display the contents of this LuxuryCar.
o Calculate TotalPrice in case transportCost is $ 20,000, and display it.

-----THE END-----

Programming in C# Page 3 of 3

You might also like