Advertisement
Guest User

Untitled

a guest
Jan 20th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. public enum CarType { DESIL, HYBRID }
  2. public class Car {
  3. CarType _type;
  4. double _km;
  5. int _prevOwners;
  6. int _year;
  7. boolean _isCab;
  8. public Car(CarType type, int year) {
  9. _type = type;
  10. _km = 0;
  11. _prevOwners = 0;
  12. _year = year;
  13. _isCab = false;
  14. }
  15. public double getValue(int curYear) {
  16. double x, y = 0;
  17. switch (_type) {
  18. case DESIL:
  19. x = 100000 * Math.max((20 - (curYear - _year)) / 20, 0.1);
  20. if (_isCab) {
  21. y = x * 0.5;
  22. } else {
  23. y = Math.max(x * 0.1, x + x * 0.1 * ((20000 –
  24. _km / (curYear - _year + 1)) / 20000));
  25. }
  26. break;
  27. case HYBRID:
  28. x = 120000 * Math.max((10 - (curYear - _year)) / 10, 0.2);
  29. y = (Math.max(100000 - _km, 0) / 100000) * x;
  30. y = x * Math.max(3 - _prevOwners, 3) / 3 + y + 2500;
  31. y = Math.max(x * 0.2, y);
  32. break;
  33. }
  34. y = Math.max(0, y);
  35. return y;
  36. }
  37. // ...
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement