Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

If you follow too close behind another car and that other car stops suddenly, yo

ID: 3638669 • Letter: I

Question

If you follow too close behind another car and that other car stops suddenly, you will not be able to stop in time, and you will crash into the rear of that other car. The following formula gives the distance between you and the car in front which allows you to stop safely: stoppingDistance = speed * (2.25 + speed / 21)

Write a program which determines whether a vehicle's tailgating distance is safe. The program should read in the speed of the vehicle and the vehicle's tailgating distance. The program should then calculate the distance that would be required to stop the vehicle.
(1) if the stopping distance is less than the tailgating distance, the program should print NO PROBLEM
(2) if the stopping distance equals the tailgating distance, the program should print MINOR WRECK
(3) if the stopping distance is greater than the tailgating distance, the program should print MAJOR WRECK

how do i write a program for this using java?

Explanation / Answer

please rate - thanks

import java.util.*;
public class main
{
public static void main(String [] args)
{ double tail,speed,stopping;
Scanner in=new Scanner(System.in);
System.out.print("Enter your speed: ");
speed=in.nextDouble();
System.out.print("Enter your tailgating distance: ");
tail=in.nextDouble();
stopping=speed*(2.25+speed/21.);
if(stopping<tail)
     System.out.println("NO PROBLEM");
else if(stopping==tail)
      System.out.println("MINOR WRECK");
else
     System.out.println("TOTAL WRECK");
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote