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 Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. System.out.println("Система расчёта штрафов");
  13.  
  14. check(60, 0);
  15. check(90, 500);
  16. check(110, 1000);
  17. check(130, 2000);
  18. check(150, 5000);
  19. }
  20.  
  21. public static void check(int carSpeed, int fine)
  22. {
  23. if(calculateFine(carSpeed) != fine) {
  24. System.out.println("Неверный штраф " + fine + " для скорости " + carSpeed);
  25. }
  26. else {
  27. System.out.println("Штраф" + fine + " для скорости " + carSpeed + " рассчитан верно ");
  28. }
  29. }
  30.  
  31. public static int calculateFine(int carSpeed)
  32. {
  33. int fineFor20to40 = 500;
  34. int fineFor40to60 = 1000;
  35. int fineFor60to80 = 2000;
  36. int fineFor80andMore = 5000;
  37.  
  38. int townSpeed = 60;
  39.  
  40. int overSpeed = carSpeed - townSpeed;
  41.  
  42. if(overSpeed < 20) {
  43. return 0;
  44. }
  45.  
  46. if(overSpeed >= 20 && overSpeed < 40) {
  47. return fineFor20to40;
  48. }
  49.  
  50. if(overSpeed >= 40 && overSpeed < 60) {
  51. return fineFor40to60;
  52. }
  53.  
  54. if(overSpeed >= 60 && overSpeed < 80) {
  55. return fineFor60to80;
  56. }
  57. else {
  58. return fineFor80andMore;
  59. }
  60. }
  61. }
Success #stdin #stdout 0.14s 55832KB
stdin
Standard input is empty
stdout
Система расчёта штрафов
Штраф0 для скорости 60 рассчитан верно 
Штраф500 для скорости 90 рассчитан верно 
Штраф1000 для скорости 110 рассчитан верно 
Штраф2000 для скорости 130 рассчитан верно 
Штраф5000 для скорости 150 рассчитан верно