first commit
This commit is contained in:
commit
6ad15af53b
8 files changed
+119
No files matched your search
@@ -0,0 +1,37 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class RadaresDeTramo {
|
||||
public static void main() {
|
||||
Scanner sc = new Scanner(System.in);
|
||||
int distancia = 0; // Distancia entre las cámaras (metros)
|
||||
int velPermitida = 0; // Velocidad máxima permitida (Km/h)
|
||||
int tiempo = 0; // Tiempo que tarda el coche en pasar entre las cámaras (segundos)
|
||||
|
||||
while(true) { // Condición de salida después de obtener datos
|
||||
System.out.print("Introduce los datos: ");
|
||||
distancia = sc.nextInt();
|
||||
velPermitida = sc.nextInt();
|
||||
tiempo = sc.nextInt();
|
||||
sc.nextLine(); // Limpiar stdin
|
||||
// Salir del bucle
|
||||
if (distancia == 0 && velPermitida == 0 && tiempo == 0) {
|
||||
System.out.println("SALIR");
|
||||
break;
|
||||
}
|
||||
// Calcular
|
||||
double velocidad = (distancia / 1000.0) / (tiempo / 3600.0); // m/s => Km/h
|
||||
if (velocidad > velPermitida){
|
||||
// indicará "MULTA" si se superó esa velocidad en menos de un 20% de la velocidad máxima permitida,
|
||||
// y "PUNTOS" si la velocidad fue superada en un 20% o más de esa velocidad;
|
||||
double rangoMulta = velPermitida * 20 / 100; // Rango que decide si te multan o te quitan puntos
|
||||
if(velocidad < velPermitida + rangoMulta){
|
||||
System.out.println("MULTA");
|
||||
} else {
|
||||
System.out.println("PUNTOS");
|
||||
}
|
||||
} else {
|
||||
System.out.println("OK");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user