Advertisement
Guest User

Untitled

a guest
Dec 10th, 2020
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. package ConditionalStatementMoreExercises;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Pets {
  6. public static void main(String[] args) {
  7. Scanner scanner = new Scanner(System.in);
  8. int days = Integer.parseInt(scanner.nextLine());
  9. int food = Integer.parseInt(scanner.nextLine());
  10. double dogFood = Double.parseDouble(scanner.nextLine());
  11. double catFood = Double.parseDouble(scanner.nextLine());
  12. double turtleFoodInGrams = Double.parseDouble(scanner.nextLine());
  13. double left = 0;
  14.  
  15. double catAndDogFood = days * (dogFood + catFood);
  16. double turtleFood = days * turtleFoodInGrams / 1000;
  17. double total = catAndDogFood + turtleFood;
  18. if (food >= total) {
  19. left = food - total;
  20. System.out.printf("%.0f kilos of food left.", Math.floor(left));
  21. } else {
  22. left = total - food;
  23. System.out.printf("%.0f more kilos of food are needed.", Math.ceil(left));
  24. }
  25. }
  26. }
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement