hpilo

Chapter2_SyntaxA_Ex7

Dec 15th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.91 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. /*  ==================================================
  4.       Chapter 2: Syntax section A- conditional clause
  5.  
  6.                   Ex7: Fuel Tank
  7.     ===================================================
  8.  */
  9.  
  10.  
  11. public class MyProgram {
  12.     public static void main(String[] args) {
  13.  
  14.         //variables
  15.         final double QUANTITY=0.15;
  16.         int maxTank;
  17.         int currentTank;
  18.         Scanner s=new Scanner(System.in);
  19.  
  20.         //user input
  21.         System.out.println("What is your max fuel tank? ");
  22.         maxTank=s.nextInt();
  23.         System.out.println("How much fuel you have now? ");
  24.         currentTank=s.nextInt();
  25.  
  26.         //check if refuel is needed and display message
  27.         if(maxTank*QUANTITY >= currentTank)
  28.             System.out.println("Go to a nearby gas station to refuel");
  29.         else
  30.             System.out.println("you can drive!");
  31.  
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment