Didart

Guinea Pig

Oct 12th, 2021
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.33 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class GuineaPig {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         double food = Double.parseDouble(scanner.nextLine());
  8.         double hay = Double.parseDouble(scanner.nextLine());
  9.         double cover = Double.parseDouble(scanner.nextLine());
  10.         double weight = Double.parseDouble(scanner.nextLine());
  11.  
  12.         double foodGr = food * 1000;
  13.         double hayGr = hay * 1000;
  14.         double coverGr = cover * 1000;
  15.         double weightGr = weight * 1000;
  16.  
  17.         int days = 1;
  18.         while (days <= 30) {
  19.  
  20.             foodGr -= 300;
  21.  
  22.             if (days % 2 == 0) {
  23.                 hayGr -= (foodGr * 5) / 100;
  24.             }
  25.             if (days % 3 == 0) {
  26.                 coverGr -= weightGr * 0.3333;
  27.             }
  28.             days++;
  29.         }
  30.         double foodKg = foodGr / 1000;
  31.         double hayKg = hayGr / 1000;
  32.         double coverKg = coverGr / 1000;
  33.  
  34.         if (foodKg >= 0 && hayKg >= 0 && coverKg >= 0) {
  35.             System.out.printf("Everything is fine! Puppy is happy! Food: %.2f, Hay: %.2f, Cover: %.2f.",
  36.                     foodKg, hayKg, coverKg);
  37.  
  38.         } else if (foodKg < 0 || hayKg < 0 || coverKg < 0) {
  39.             System.out.println("Merry must go to the pet store!");
  40.         }
  41.     }
  42. }
  43.  
Advertisement
Add Comment
Please, Sign In to add comment