borovaneca

GiuneaPig

Jan 17th, 2023
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.40 KB | None | 0 0
  1. package Fundamentals.Exams;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class GuineaPig {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.  
  10.         double foodQuantity = Double.parseDouble(scanner.nextLine()) * 1000;
  11.         double hayQuantity = Double.parseDouble(scanner.nextLine()) * 1000;
  12.         double coverQuantity = Double.parseDouble(scanner.nextLine()) * 1000;
  13.         double guineaWeight = Double.parseDouble(scanner.nextLine()) * 1000;
  14.  
  15.         int dayCount = 0;
  16.         while (dayCount < 30 && foodQuantity >0 && hayQuantity > 0 && coverQuantity > 0) {
  17.             dayCount++;
  18.             foodQuantity -= 300;
  19.             if (dayCount % 2 == 0) {
  20.                 hayQuantity = hayQuantity - (hayQuantity * 0.5);
  21.             }
  22.             if (dayCount % 3 == 0) {
  23.                 coverQuantity = coverQuantity - (guineaWeight * 1/3);
  24.             }
  25.         }
  26.         foodQuantity = foodQuantity / 1000;
  27.         hayQuantity =  hayQuantity / 1000;
  28.         coverQuantity = coverQuantity / 1000;
  29.  
  30.         boolean checker = foodQuantity >0 && hayQuantity > 0 && coverQuantity > 0;
  31.         if (checker) {
  32.             System.out.printf("Everything is fine! Puppy is happy! Food: %.2f, Hay: %.2f, Cover: %.2f.", foodQuantity, hayQuantity, coverQuantity);
  33.         } else {
  34.             System.out.println("Merry must go to the pet store!");
  35.         }
  36.     }
  37. }
  38.  
Advertisement
Add Comment
Please, Sign In to add comment