fork download
  1. class Ideone
  2. {
  3. public static void main (String[] args) throws java.lang.Exception
  4. {
  5. System.out.println("Система расчёта штрафов");
  6.  
  7. int carSpeed = 187;
  8.  
  9. if (calculate(500) != 5000) {
  10. System.out.println("Неверный штраф для скорости 500: 5000 р.");
  11. }
  12. else {
  13. System.out.println("Iтраф для скорости 500: верно 5000 р.");
  14. }
  15. System.out.println("Штраф: " + calculate(carSpeed) + " рублей");
  16. }
  17. public static int calculate(int carSpeed)
  18. {
  19. int fineFor20to40 = 500;
  20. int fineFor40to60 = 1000;
  21. int fineFor60to80 = 2000;
  22. int fineFor80andMore = 5000;
  23.  
  24. int townSpeed = 60;
  25.  
  26. int overSpeed = carSpeed - townSpeed;
  27.  
  28. if(overSpeed < 20) {
  29. return 0;
  30. }
  31. if(overSpeed >= 20 && overSpeed < 40) {
  32. return fineFor20to40;
  33. }
  34. if(overSpeed >= 40 && overSpeed < 60) {
  35. return fineFor40to60;
  36. }
  37. if(overSpeed >= 60 && overSpeed < 80) {
  38. return fineFor60to80;
  39. }
  40. else {
  41. return fineFor80andMore;
  42. }
  43. }
  44. }
Success #stdin #stdout 0.13s 57532KB
stdin
Standard input is empty
stdout
Система расчёта штрафов
Iтраф для скорости 500: верно 5000 р.
Штраф: 5000 рублей