Advertisement
desislava_topuzakova

02.FriendlyTrip

Mar 11th, 2018
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.90 KB | None | 0 0
  1. package TestJan;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class FriendlyTrip {
  6.     public static void main(String[] args) {
  7.         Scanner scan = new Scanner(System.in);
  8.  
  9.         double km = Double.parseDouble(scan.nextLine());
  10.         double fuelConsumption = Double.parseDouble(scan.nextLine());
  11.         double fuelPrice = Double.parseDouble(scan.nextLine());
  12.         double sum = Double.parseDouble(scan.nextLine());
  13.  
  14.         double carConsumption = (km *fuelConsumption) / 100;
  15.         double costs = carConsumption * fuelPrice;
  16.         double totalMoneyLeft = costs - sum;
  17.  
  18.         if(totalMoneyLeft <= 0){
  19.             System.out.printf("You can take a trip. %.2f money left.", Math.abs(totalMoneyLeft));
  20.         }else{
  21.             double pricePerPerson = sum /5;
  22.             System.out.printf("Sorry, you cannot take a trip. Each will receive %.2f money.", pricePerPerson);
  23.         }
  24.  
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement