Viết chương trình quản lý xe car bằng C # - C Sharp | Khoá học lập trình C#
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.
● Create two constructors and all method get/set for its attributes
● Implement method calculateTax() to calculate the Tax as follows:
○ If the car has under 7 seats then tax = RootPrice * 60%.
○ Else tax = RootPrice * 70%
● Implement method calculatePrice() to calculate TotalPrice as follows:
○ 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 $).
- Declaring class LuxuryCar inherits from class Car and adding follow attrubtes :
private float specialRate;
● Create two constructors and all method get/set for its attributes
● 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: TotalPrice = RootPrice + Tax + RootPrice * specialRate + transportCost.
- Create a class named Test.
● Declare and initialize 1 instance named “myLuxuryCar” of class LuxuryCar.
○ Input Name, Producer, Year, Seat, rootPrice from the keyboard (Catch exception when input value). Display the contents of this LuxuryCar.
○ Calculate TotalPrice in case transportCost is $ 20,000, and display it.