Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.text.DecimalFormat;
- public class Assi3q1
- {
- public static void main(String[] args)
- {
- double distanceRemain, gasRemain, avgFuelCons, howFar, distanceLeft;
- Scanner keyboard = new Scanner(System.in);
- System.out.print("Enter the distance remaining in your journey (in km.): ");
- distanceRemain = keyboard.nextDouble();
- System.out.print("Enter the gas remaining in your tank (in liters): ");
- gasRemain = keyboard.nextDouble();
- System.out.print("Enter average fuel consumption (in liters/100 km.): ");
- avgFuelCons = keyboard.nextDouble();
- howFar = (gasRemain*100)/avgFuelCons;
- distanceLeft = (distanceRemain - howFar);
- DecimalFormat value= new DecimalFormat("0.00");
- if (distanceLeft <= distanceRemain)
- System.out.print ("Warning! Running out of gas.\n" + "The car will stop " + distanceLeft + "km. from your destination." );
- else if (distanceLeft > distanceRemain)
- System.out.print ("Warning! Running out of gas.\n" + "The car will stop " + distanceLeft + "km. from your destination." );
- else
- System.out.print("Invalid");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement