Advertisement
KeepCoding

Pipes In Pool

Oct 27th, 2017
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.20 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class testin {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int v = Integer.parseInt(scanner.nextLine());
  7.         int p1 = Integer.parseInt(scanner.nextLine());
  8.         int p2 = Integer.parseInt(scanner.nextLine());
  9.         double h = Double.parseDouble(scanner.nextLine());
  10.         double p1h = p1 * h;
  11.         double p2h = p2 * h;
  12.         if (p1h + p2h > v) {
  13.             double overflow = (p1h + p2h) - v;
  14.             System.out.printf("For %f hours the pool overflows with %f liters", h, overflow);
  15.         } else {
  16.             double vp = p1h + p2h;
  17. //            long percentage1 = Math.round((p1h / vp) * 100);
  18. //            long percentage2 = Math.round((p2h / vp) * 100);
  19.             double percentage1 = Math.floor((p1h / vp) * 100);
  20.             double percentage2 = Math.floor((p2h / vp) * 100);
  21. //            long percentageFull = Math.round((vp / v) * 100);
  22.             double percentageFull = Math.floor((vp / v) * 100);
  23.             System.out.printf("The pool is %f%% full. Pipe 1: %f%%. Pipe 2: %f%%.", percentageFull, percentage1, percentage2);
  24.         }
  25.         //code ends here
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement