Advertisement
finderabc

GoingHomeExam

Sep 12th, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.85 KB | None | 0 0
  1. package SimpleOperationsAndCalculationsExercise;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class GoingHomeExam {
  6.     public static void main(String[] args) {
  7.  
  8.         Scanner scan = new Scanner(System.in);
  9.  
  10.         int km = Integer.parseInt(scan.nextLine());
  11.         int costFuelKm = Integer.parseInt(scan.nextLine());
  12.         double priceFuelLiter = Double.parseDouble(scan.nextLine());
  13.         double money = Double.parseDouble(scan.nextLine());
  14.  
  15.         double costFuelCar = km * (costFuelKm / 100);
  16.         double sumCost = costFuelCar * priceFuelLiter;
  17.  
  18.  
  19.         if (money >= sumCost) {
  20.             money = money - sumCost;
  21.             System.out.printf("You can go home. %.2f money left.", money);
  22.         } else {
  23.             System.out.printf("Sorry, you cannot go home. Each will receive %.2f money.",money /5  );
  24.         }
  25.  
  26.     }
  27.  
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement