Write a java program that can be used by a policeman to determine if a vehicle has exceeded the speed limit and to levy a fine. The policeman should enter the vehicles speed and the speed limit. If the speed limit is exceeded by less than 30kph a fine of Kshs. 2500 should be charged. Otherwise a fine of Kshs 4000 is charged. Your program should then output (in a suitable format) the vehicle speed, the speed limit, the excess speed and the fine levied.
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter the vehicles speed (kph):");
int vehiclesSpeed = Integer.parseInt(scanner.nextLine());
System.out.println("Enter the limit speed (kph):");
int limitSpeed = Integer.parseInt(scanner.nextLine());
int fine = 0;
if (vehiclesSpeed - limitSpeed < 30 && vehiclesSpeed - limitSpeed > 0){
fine = 2500;
} else if (vehiclesSpeed - limitSpeed >= 30) {
fine = 4000;
}
if (fine != 0) {
System.out.println("The vehicle speed: " + vehiclesSpeed + " kph");
System.out.println("The speed limit: " + limitSpeed + " kph");
System.out.println("The excess speed: " + (vehiclesSpeed - limitSpeed) + " kph");
System.out.println("Fine levied: " + fine + " Kshs");
} else {
System.out.println("The speed is normal");
}
}
Comments
Leave a comment