90 lines
1.3 KiB
C++
90 lines
1.3 KiB
C++
#include "Car.h"
|
|
#include "TaxRates.h"
|
|
|
|
Car::Car(double worth,
|
|
double horsepower)
|
|
: Property(worth)
|
|
{
|
|
this->horsepower = horsepower;
|
|
}
|
|
|
|
double Car::calculateTax()
|
|
{
|
|
if (horsepower <
|
|
TAX_RATES::LOW_HORSEPOWER)
|
|
{
|
|
return worth *
|
|
TAX_RATES::CAR_TAX;
|
|
}
|
|
|
|
if (horsepower <=
|
|
TAX_RATES::HIGH_HORSEPOWER)
|
|
{
|
|
return worth *
|
|
TAX_RATES::CAR_TRUCK_TAX;
|
|
}
|
|
|
|
return worth *
|
|
TAX_RATES::CAR_LUXURY_TAX;
|
|
}
|
|
|
|
void Car::fromJson(json j)
|
|
{
|
|
worth = j["worth"];
|
|
|
|
horsepower =
|
|
j["horsepower"];
|
|
}
|
|
|
|
json Car::toJson()
|
|
{
|
|
json j;
|
|
|
|
j["worth"] = worth;
|
|
|
|
j["horsepower"] =
|
|
horsepower;
|
|
|
|
j["tax"] =
|
|
calculateTax();
|
|
|
|
return j;
|
|
}
|
|
|
|
void Car::fromXml(
|
|
XMLElement* element)
|
|
{
|
|
element->QueryDoubleAttribute(
|
|
"worth",
|
|
&worth
|
|
);
|
|
|
|
element->QueryDoubleAttribute(
|
|
"horsepower",
|
|
&horsepower
|
|
);
|
|
}
|
|
|
|
XMLElement* Car::toXml(
|
|
XMLDocument& doc)
|
|
{
|
|
XMLElement* element =
|
|
doc.NewElement("Car");
|
|
|
|
element->SetAttribute(
|
|
"worth",
|
|
worth
|
|
);
|
|
|
|
element->SetAttribute(
|
|
"horsepower",
|
|
horsepower
|
|
);
|
|
|
|
element->SetAttribute(
|
|
"tax",
|
|
calculateTax()
|
|
);
|
|
|
|
return element;
|
|
} |