Advertisement
marking2112

Friendly Trip

Jun 13th, 2018
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.93 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Demo {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         double destination = Double.parseDouble(scanner.nextLine());
  8.         double consumption = Double.parseDouble(scanner.nextLine());
  9.         double fuelPrice = Double.parseDouble(scanner.nextLine());
  10.         double money = Double.parseDouble(scanner.nextLine());
  11.  
  12.         double carConsump = destination * (consumption / 100);
  13.         double moneyNeeded = carConsump * fuelPrice;
  14.  
  15.  
  16.         if (money >= moneyNeeded) {
  17.             double result = money - moneyNeeded;
  18.             System.out.printf("You can take a trip. %.2f money left.", result);
  19.         } else {
  20.             double result = moneyNeeded - money;
  21.             double resultother = result / 4;
  22.             System.out.printf("Sorry, you cannot take a trip. Each will receive %.2f money.", resultother);
  23.         }
  24.  
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement