Advertisement
ivanov_ivan

PoolsHelp

Feb 10th, 2017
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.17 KB | None | 0 0
  1. package helper;
  2.  
  3. import java.text.DecimalFormat;
  4. import java.util.Scanner;
  5.  
  6. public class Pools {
  7.     public static void main(String[] args) {
  8.         Scanner scanner = new Scanner(System.in);
  9.  
  10.         int v = Integer.parseInt(scanner.nextLine());
  11.         int p1 = Integer.parseInt(scanner.nextLine());
  12.         int p2 = Integer.parseInt(scanner.nextLine());
  13.         double H = Double.parseDouble(scanner.nextLine());
  14.  
  15.         double pipe1 = p1 * H;
  16.         double pipe2 = p2 * H;
  17.         double total = pipe1 + pipe2;
  18.         double pool = (total / v) * 100;
  19.         double overflows = total -  v;
  20.  
  21.         DecimalFormat format = new DecimalFormat("#.###############");
  22.         if (v>=total) {
  23.             int pip1 = (int) ((pipe1/total)*100);
  24.             int pip2 = (int) ((pipe2/total)*100);
  25.             int fullpool = (int) pool;
  26.             System.out.printf("The pool is %s%% full. Pipe 1: %s%%. Pipe 2: %s%%.", format.format(fullpool)
  27.                     , format.format(pip1), format.format(pip2));
  28.         } else {
  29.             System.out.printf("For %s hours the pool overflows with %s liters.", format.format(H), format.format(overflows));
  30.         }
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement