Ad
Arrays

The police have placed radars that will detect those vehicles that exceed the speed limit on that road. If the driver's speed is 10km/h to 19km/h above the speed limit, the fine will be 100 euros, if it is exceeded by 20km/h to 29km/h the fine will be 250 euros and if it is exceeded by more than 30km/h the fine will be 500 euros.

You will be provided with the speed limits of those roads with radar as an array of integers (int speeds [90,100,110,120,....]) and the speed of the driver will be the same on all roads and the amount of the fine will be accumulated (example 95km/h).

Code
Diff
  • public class Kata {
        
        public static int speedLimit(int speed, int[] signals) {
          int penalty = 0;
          
          for (int i = 0; i < signals.length; i++){
            if (speed > signals[i]){
              if (speed - signals[i] >= 30){
                penalty += 500;
              } else if (speed - signals[i] >= 20 && speed - signals[i] < 30){
                penalty += 250;
              } else if (speed - signals[i] >= 10 && speed - signals[i] < 20){
                penalty += 100;
              }
            }
          }
          
          return penalty;
        }
    }
    • public class Kata {
    • public static int speedLimit(int speed, int[] signals) {
    • int penalty = 0;
    • for (int i = 0; i < signals.length; i++){
    • if (speed > signals[i]){
    • if (speed - signals[i] >= 30){
    • penalty += 500;
    • } else if (speed - signals[i] >= 20 && speed - signals[i] < 30){
    • penalty += 250;
    • } else if (speed - signals[i] >= 10 && speed - signals[i] < 20){
    • penalty += 100;
    • }
    • }
    • }
    • return penalty;
    • }
    • }

The DGT has placed radars on several highways in Madrid that will detect those vehicles that exceed the speed limit allowed on that road. If the driver's speed is 10km/h to 19km/h above the speed limit, the fine will be 100 euros, if it is exceeded by 20km/h to 29km/h the fine will be 250 euros and if it is exceeded by more than 30km/h the fine will be 500 euros.

You will be provided with the speed limits of those roads with radar as an array of integers(int speeds [90,100,110,120,120,....]).

public class SpeedLimit{
  public static int sequence(int[] arr) {
    return 0;
  }
}