Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public enum CarType { DESIL, HYBRID }
- public class Car {
- CarType _type;
- double _km;
- int _prevOwners;
- int _year;
- boolean _isCab;
- public Car(CarType type, int year) {
- _type = type;
- _km = 0;
- _prevOwners = 0;
- _year = year;
- _isCab = false;
- }
- public double getValue(int curYear) {
- double x, y = 0;
- switch (_type) {
- case DESIL:
- x = 100000 * Math.max((20 - (curYear - _year)) / 20, 0.1);
- if (_isCab) {
- y = x * 0.5;
- } else {
- y = Math.max(x * 0.1, x + x * 0.1 * ((20000 –
- _km / (curYear - _year + 1)) / 20000));
- }
- break;
- case HYBRID:
- x = 120000 * Math.max((10 - (curYear - _year)) / 10, 0.2);
- y = (Math.max(100000 - _km, 0) / 100000) * x;
- y = x * Math.max(3 - _prevOwners, 3) / 3 + y + 2500;
- y = Math.max(x * 0.2, y);
- break;
- }
- y = Math.max(0, y);
- return y;
- }
- // ...
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement