Advertisement
Spocoman

08. Fuel Tank - Part 2

Aug 24th, 2024
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.22 KB | None | 0 0
  1. import java.util.Objects;
  2. import java.util.Scanner;
  3.  
  4. public class FuelTank2 {
  5.     public static void main(String[] args) {
  6.         Scanner scanner = new Scanner(System.in);
  7.         String fuel = scanner.nextLine();
  8.         double liters = Double.parseDouble(scanner.nextLine());
  9.         String cart = scanner.nextLine();
  10.         double literPrice = 0;
  11.  
  12.         if (Objects.equals(cart, "No")) {
  13.             if (Objects.equals(fuel, "Gas")) {
  14.                 literPrice = 0.93;
  15.             } else if (Objects.equals(fuel, "Gasoline")) {
  16.                 literPrice = 2.22;
  17.             } else if (Objects.equals(fuel, "Diesel")) {
  18.                 literPrice = 2.33;
  19.             }
  20.         } else {
  21.             if (Objects.equals(fuel, "Gas")) {
  22.                 literPrice = 0.85;
  23.             } else if (Objects.equals(fuel, "Gasoline")) {
  24.                 literPrice = 2.04;
  25.             } else if (Objects.equals(fuel, "Diesel")) {
  26.                 literPrice = 2.21;
  27.             }
  28.         }
  29.  
  30.         if (liters >= 20 && liters <= 25) {
  31.             literPrice *= 0.92;
  32.         } else if (liters > 25) {
  33.             literPrice *= 0.9;
  34.         }
  35.  
  36.         System.out.printf("%.2f lv.\n", literPrice * liters);
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement