Answer to Question #311369 in Java | JSP | JSF for Jay

Question #311369

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.



1
Expert's answer
2022-03-15T20:00:29-0400
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");
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS