fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Main
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. System.out.println("Система расчёта штрафов в Германии");
  13.  
  14. check(55, 30);
  15. check(63, 50);
  16. check(68, 70);
  17. check(73, 115);
  18. check(78, 180);
  19. check(83, 260);
  20. check(95, 400);
  21. check(105, 560);
  22. check(115, 700);
  23. check(130, 800);
  24. }
  25.  
  26. public static void check(int carSpeed, int fine)
  27. {
  28. if(calculateFine(carSpeed) != fine) {
  29. System.out.println("Неверный штраф " + fine + " для скорости " + carSpeed);
  30. }
  31. else {
  32. System.out.println("Штраф " + fine + " для скорости " + carSpeed + " рассчитан верно");
  33. }
  34. }
  35.  
  36. public static int calculateFine(int carSpeed)
  37. {
  38.  
  39. boolean isTown = true;
  40.  
  41. int fineFor1to10 = 30;
  42. int fineFor11to15 = 50;
  43. int fineFor16to20 = 70;
  44. int fineFor21to25 = 115;
  45. int fineFor26to30 = 180;
  46. int fineFor31to40 = 260;
  47. int fineFor41to50 = 400;
  48. int fineFor51to60 = 560;
  49. int fineFor61to70 = 700;
  50. int fineFor70andMore = 800;
  51.  
  52. int townSpeed = 50;
  53. int countrySpeed = 90;
  54. int overSpeed = 0;
  55.  
  56. if (isTown) {
  57. overSpeed = carSpeed - townSpeed;
  58. }
  59. else {
  60. overSpeed = carSpeed - countrySpeed;
  61. }
  62.  
  63. if(overSpeed < 1) {
  64. return 0;
  65. }
  66.  
  67. else if(overSpeed >= 1 && overSpeed <= 10) {
  68. return fineFor1to10;
  69. }
  70. else if(overSpeed >= 11 && overSpeed <= 15) {
  71. return fineFor11to15;
  72. }
  73. else if(overSpeed >= 16 && overSpeed <= 20) {
  74. return fineFor16to20;
  75. }
  76. else if(overSpeed >= 21 && overSpeed <= 25) {
  77. return fineFor21to25;
  78. }
  79. else if(overSpeed >= 26 && overSpeed <= 30) {
  80. return fineFor26to30 ;
  81. }
  82. else if(overSpeed >= 31 && overSpeed <= 40) {
  83. return fineFor31to40;
  84. }
  85. else if(overSpeed >= 41 && overSpeed <= 50) {
  86. return fineFor41to50;
  87. }
  88. else if(overSpeed >= 51 && overSpeed <= 60) {
  89. return fineFor51to60;
  90. }
  91. else if(overSpeed >= 61 && overSpeed <= 70) {
  92. return fineFor61to70;
  93. }
  94.  
  95. return fineFor70andMore;
  96. }
  97. }
Success #stdin #stdout 0.14s 54168KB
stdin
Standard input is empty
stdout
Система расчёта штрафов в Германии
Штраф 30 для скорости 55 рассчитан верно
Штраф 50 для скорости 63 рассчитан верно
Штраф 70 для скорости 68 рассчитан верно
Штраф 115 для скорости 73 рассчитан верно
Штраф 180 для скорости 78 рассчитан верно
Штраф 260 для скорости 83 рассчитан верно
Штраф 400 для скорости 95 рассчитан верно
Штраф 560 для скорости 105 рассчитан верно
Штраф 700 для скорости 115 рассчитан верно
Штраф 800 для скорости 130 рассчитан верно