pastebin

Paste Search Dynamic
Recent pastes
check
  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. public class Main
  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.                 check(79, 0);
  20.                 check(80, 500);
  21.                 check(99, 500);
  22.                 check(100, 1000);
  23.                 check(119, 1000);
  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.                 int fineFor20to40 = 500;
  39.                 int fineFor40to60 = 1000;
  40.                 int fineFor60to80 = 2000;
  41.                 int fineFor80andMore = 5000;
  42.                
  43.                 int townSpeed = 60;
  44.                
  45.                 int overSpeed = carSpeed - townSpeed;
  46.                
  47.                 if(overSpeed < 20) {
  48.                         return 0;
  49.                 }
  50.                
  51.                 if(overSpeed >= 20 && overSpeed < 40) {
  52.                         return fineFor20to40;
  53.                 }
  54.                
  55.                 if(overSpeed >= 40 && overSpeed < 60) {
  56.                         return fineFor40to60;
  57.                 }
  58.                
  59.                 if(overSpeed >= 60 && overSpeed < 80) {
  60.                         return fineFor60to80;
  61.                 }
  62.                
  63.                 return fineFor80andMore;
  64.         }
  65. }
Parsed in 0.056 seconds