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(56, 0);
  15. check(67, 30);
  16. check(94, 260);
  17. check(107, 400);
  18. check(130, 800);
  19. }
  20.  
  21. public static void check(int carSpeed, int fine)
  22. {
  23. if(calculatfine(carSpeed) != fine) {
  24. System.out.println("Неверный штраф " + fine + " для скорости " + carSpeed);
  25. }
  26. else{
  27. System.out.println("Штраф " + fine + " для скорости " + carSpeed + " рассчитан верно");
  28. }
  29. }
  30.  
  31. public static int calculatfine(int carSpeed)
  32. {
  33.  
  34. int fineFor1to10 = 30;
  35. int fineFor11to15 = 50;
  36. int fineFor16to20 = 70;
  37. int fineFor21to25 = 115;
  38. int fineFor26to30 = 180;
  39. int fineFor31to40 = 260;
  40. int fineFor41to50 = 400;
  41. int fineFor51to60 = 560;
  42. int fineFor61to70 = 700;
  43. int fineFor71andMore = 800;
  44.  
  45. int townSpeed = 60;
  46.  
  47. int overSpeed = carSpeed - townSpeed;
  48.  
  49. if(overSpeed < 1) {
  50. return 0;
  51. }
  52.  
  53. if(overSpeed >= 1 && overSpeed < 10) {
  54. return fineFor1to10;
  55. }
  56.  
  57. if(overSpeed >= 11 && overSpeed < 15) {
  58. return fineFor11to15;
  59. }
  60.  
  61. if(overSpeed >= 16 && overSpeed < 20) {
  62. return fineFor16to20;
  63. }
  64.  
  65. if(overSpeed >= 21 && overSpeed < 25) {
  66. return fineFor21to25;
  67. }
  68.  
  69. if(overSpeed >= 26 && overSpeed < 30) {
  70. return fineFor26to30;
  71. }
  72.  
  73. if(overSpeed >= 31 && overSpeed < 40) {
  74. return fineFor31to40;
  75. }
  76.  
  77. if(overSpeed >= 41 && overSpeed < 50) {
  78. return fineFor41to50;
  79. }
  80.  
  81. if(overSpeed >= 51 && overSpeed < 60) {
  82. return fineFor51to60;
  83. }
  84.  
  85. if(overSpeed >= 61 && overSpeed < 70) {
  86. return fineFor61to70;
  87. }
  88. else {
  89. return fineFor71andMore;
  90. }
  91. }
  92. }
  93.  
  94.  
  95.  
Success #stdin #stdout 0.13s 57972KB
stdin
Standard input is empty
stdout
Система расчёта штрафов
Штраф 0 для скорости 56 рассчитан верно
Штраф 30 для скорости 67 рассчитан верно
Штраф 260 для скорости 94 рассчитан верно
Штраф 400 для скорости 107 рассчитан верно
Штраф 800 для скорости 130 рассчитан верно