Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.text.DecimalFormat;
  3.  
  4. public class Assi3q1
  5. {
  6. public static void main(String[] args)
  7. {
  8. double distanceRemain, gasRemain, avgFuelCons, howFar, distanceLeft;
  9.  
  10. Scanner keyboard = new Scanner(System.in);
  11.  
  12. System.out.print("Enter the distance remaining in your journey (in km.): ");
  13. distanceRemain = keyboard.nextDouble();
  14.  
  15. System.out.print("Enter the gas remaining in your tank (in liters): ");
  16. gasRemain = keyboard.nextDouble();
  17.  
  18. System.out.print("Enter average fuel consumption (in liters/100 km.): ");
  19. avgFuelCons = keyboard.nextDouble();
  20.  
  21. howFar = (gasRemain*100)/avgFuelCons;
  22.  
  23. distanceLeft = (distanceRemain - howFar);
  24. DecimalFormat value= new DecimalFormat("0.00");
  25.  
  26. if (distanceLeft <= distanceRemain)
  27. System.out.print ("Warning! Running out of gas.\n" + "The car will stop " + distanceLeft + "km. from your destination." );
  28.  
  29. else if (distanceLeft > distanceRemain)
  30. System.out.print ("Warning! Running out of gas.\n" + "The car will stop " + distanceLeft + "km. from your destination." );
  31. else
  32. System.out.print("Invalid");
  33.  
  34.  
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement