Advertisement
veronikaaa86

01. Guinea Pig

Oct 19th, 2022
1,334
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.65 KB | None | 0 0
  1. package examPrep;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class P01GuineaPig {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.         double foodQuantityKg = Double.parseDouble(scanner.nextLine());
  10.         double hayQuantityKg = Double.parseDouble(scanner.nextLine());
  11.         double coverQuantityKg = Double.parseDouble(scanner.nextLine());
  12.         double guineaWeightKg = Double.parseDouble(scanner.nextLine());
  13.  
  14.         double foodQuantityGr = foodQuantityKg * 1000;
  15.         double hayQuantityGr = hayQuantityKg * 1000;
  16.         double coverQuantityGr = coverQuantityKg * 1000;
  17.         double guineaWeightGr = guineaWeightKg * 1000;
  18.  
  19.         boolean isNotEnough = false;
  20.         for (int day = 1; day <= 30; day++) {
  21.             foodQuantityGr = foodQuantityGr - 300;
  22.             if (day % 2 == 0) {
  23.                 double currentHay = foodQuantityGr * 0.05;
  24.                 hayQuantityGr = hayQuantityGr - currentHay;
  25.             }
  26.  
  27.             if (day % 3 == 0) {
  28.                 double currentCover = guineaWeightGr / 3;
  29.                 coverQuantityGr = coverQuantityGr - currentCover;
  30.             }
  31.  
  32.             if (foodQuantityGr <= 0 || hayQuantityGr <= 0 || coverQuantityGr <= 0) {
  33.                 isNotEnough = true;
  34.                 break;
  35.             }
  36.         }
  37.  
  38.         if (isNotEnough) {
  39.             System.out.println("Merry must go to the pet store!");
  40.         } else {
  41.             System.out.printf("Everything is fine! Puppy is happy! Food: %.2f, Hay: %.2f, Cover: %.2f.",
  42.                     foodQuantityGr / 1000, hayQuantityGr / 1000, coverQuantityGr / 1000);
  43.         }
  44.     }
  45. }
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement