Advertisement
mark79

Fuel Tank - Part 2

Jul 18th, 2019
510
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.00 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class FuelTankPart2 {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         String fuelType = scanner.nextLine();
  8.         int fuelQty = Integer.parseInt(scanner.nextLine());
  9.         String discountCard = scanner.nextLine();
  10.  
  11.         double fuelPrice = 0;
  12.         switch (fuelType) {
  13.             case "Gas":
  14.                 fuelPrice = discountCard.equals("Yes") ? 0.93 - 0.08 : 0.93;
  15.                 break;
  16.             case "Gasoline":
  17.                 fuelPrice = discountCard.equals("Yes") ? 2.22 - 0.18 : 2.22;
  18.                 break;
  19.             case "Diesel":
  20.                 fuelPrice = discountCard.equals("Yes") ? 2.33 - 0.12 : 2.33;
  21.                 break;
  22.         }
  23.  
  24.         if (fuelQty > 25) {
  25.             fuelPrice *= 0.9;
  26.         } else if (fuelQty >= 20) {
  27.             fuelPrice *= 0.92;
  28.         }
  29.  
  30.         double result = fuelQty * fuelPrice;
  31.         System.out.printf("%.2f lv.", result);
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement