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).
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;
}
}
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
// TODO: Replace examples and use TDD by writing your own tests
class SolutionTest {
@Test
void testSomething() {
// assertEquals("expected", "actual");
}
}