borovaneca

Guinea Pig

Jan 17th, 2023
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.25 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()) * 100;
  13.         double guineaWeight = Double.parseDouble(scanner.nextLine()) * 100;
  14.  
  15.         int days = 1;
  16.  
  17.         while (days <= 30) {
  18.  
  19.             foodQuantity -= 300;
  20.             if (days % 2 == 0) {
  21.                 hayQuantity -= foodQuantity * 0.05;
  22.             }
  23.             if (days % 3 == 0) {
  24.                 coverQuantity -= guineaWeight / 3;
  25.             }
  26.             days++;
  27.         }
  28.  
  29.         foodQuantity /= 1000;
  30.         hayQuantity /= 1000;
  31.         coverQuantity /= 1000;
  32.         boolean checker = foodQuantity >0 && hayQuantity > 0 && coverQuantity > 0;
  33.         if (checker) {
  34.             System.out.printf("Everything is fine! Puppy is happy! Food: %.2f, Hay: %.2f, Cover: %.2f.", foodQuantity, hayQuantity, coverQuantity);
  35.         } else {
  36.             System.out.println("Merry must go to the pet store!");
  37.         }
  38.     }
  39. }
  40.  
Advertisement
Add Comment
Please, Sign In to add comment