Advertisement
Guest User

Untitled

a guest
Mar 12th, 2017
361
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.39 KB | None | 0 0
  1. import java.math.BigDecimal;
  2. import java.math.RoundingMode;
  3. import java.util.Scanner;
  4.  
  5. public class Ex02Harvest {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.         BigDecimal area = new BigDecimal(scanner.nextLine());
  9.         BigDecimal harvestFromOneSqM = new BigDecimal(scanner.nextLine());
  10.         BigDecimal neededWine = new BigDecimal(scanner.nextLine());
  11.         BigDecimal workers = new BigDecimal(scanner.nextLine());
  12.  
  13.         BigDecimal producedWine = harvestFromOneSqM.multiply(area);
  14.         producedWine = producedWine.multiply(new BigDecimal("0.4")
  15.                 .divide(new BigDecimal("2.5"), 2, BigDecimal.ROUND_HALF_UP));
  16.  
  17.         if (neededWine.compareTo(producedWine) == 1) {
  18.             System.out.printf("It will be a tough winter! More %d liters wine needed.%n",
  19.                     neededWine.subtract(producedWine).intValue());
  20.         } else {
  21.             System.out.printf("Good harvest this year! Total wine: %d liters.%n", producedWine.toBigInteger());
  22.             System.out.printf("%d liters left -> %d liters per person.%n",
  23.                     producedWine.subtract(neededWine).setScale(0, RoundingMode.UP).intValue(),
  24.                     producedWine.subtract(neededWine).divide(workers, 2, BigDecimal.ROUND_HALF_UP)
  25.                             .setScale(0, RoundingMode.UP).intValue());
  26.         }
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement