galinyotsev123

ProgBasicsExam11and12August2018-E02goingHome

Jan 2nd, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class E02goingHome {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6.  
  7. double boys = 5;
  8. double km = Double.parseDouble(scanner.nextLine()); // 120
  9. double litreFuel = Double.parseDouble(scanner.nextLine()); // 5
  10. double priceFuel = Double.parseDouble(scanner.nextLine()); //1.2
  11. double budget = Double.parseDouble(scanner.nextLine());//4
  12.  
  13. double fuelPer100km = (km * litreFuel) / 100;
  14.  
  15. double moneyForFuel = fuelPer100km * priceFuel;
  16.  
  17.  
  18. if (budget >= moneyForFuel) {
  19. System.out.printf("You can go home. %.2f money left.", budget - moneyForFuel);
  20. } else {
  21. double eachPlayer = budget / boys;
  22. System.out.printf("Sorry, you cannot go home. Each will receive %.2f money.",eachPlayer);
  23. }
  24.  
  25. }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment