Please Help with range of uncertainty in java program
807580Feb 23 2010 — edited Feb 24 2010I really need help with this, I've been searching for an answer all day and have found nothing.
This is the original program and I'm trying to make it so instead of stoppingDistance having to be equal to tailgateDistance for it to print minor wreck, it will allow a range of 40 feet. Like a range of uncertainty of plus or minus 20 feet, and I need to use a named constant that is: RANGE = 40.0
import java.util.Scanner;
public class StoppingA
{
public static void main(String[] args)
{
Scanner stdIn = new Scanner(System.in);
double speed; // speed car is traveling;
double tailgateDistance; // distance from other car;
double stoppingDistance; // calculated distance
System.out.print ("Enter your speed (in mph): ");
speed = stdIn.nextDouble();
System.out.print ("Enter your tailgate distance (in feet): ");
tailgateDistance = stdIn.nextDouble();
stoppingDistance=speed*(2.25+speed/21);
if (stoppingDistance < tailgateDistance)
{
System.out.println("No problem.");
}
else if (stoppingDistance == tailgateDistance)
{
System.out.println("Minor wreck.");
}
else if (stoppingDistance > tailgateDistance)
{
System.out.println("Major wreck!");
}
} // end main
} // end class StoppingA
Edited by: Ensanvoration on Feb 23, 2010 3:31 PM