desislava_topuzakova

06. Honey Winter Reserves

Jun 10th, 2020
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.10 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class HoneyWinterReserves_06 {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         double quantity = Double.parseDouble(scanner.nextLine());
  8.         String name = scanner.nextLine();
  9.         while (!name.equals("Winter has come"))
  10.         {
  11.             double total = 0;
  12.             for (int i = 1; i <= 6; i++)
  13.             {
  14.                 double collectedHoney = Double.parseDouble(scanner.nextLine());
  15.                 total += collectedHoney;
  16.             }
  17.             if (total < 0)
  18.             {
  19.                 System.out.printf("%s was banished for gluttony%n", name);
  20.             }
  21.  
  22.             quantity -= total;
  23.             if (quantity <= 0)
  24.             {
  25.                 break;
  26.             }
  27.             name = scanner.nextLine();
  28.         }
  29.  
  30.         if (quantity > 0)
  31.         {
  32.             System.out.printf("Hard Winter! Honey needed %.2f.", quantity);
  33.         }
  34.         else
  35.         {
  36.             System.out.printf("Well done! Honey surplus %.2f.", Math.abs(quantity));
  37.         }
  38.     }
  39. }
Add Comment
Please, Sign In to add comment