Advertisement
musakahero

Untitled

Jul 16th, 2017
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.09 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class poolPipes {
  4.     public static void main(String[] args) {
  5.  
  6.         Scanner scanner = new Scanner(System.in);
  7.  
  8.         //inputvariables
  9.         int V = Integer.parseInt(scanner.nextLine()); //volume of pool in litres
  10.         int P1 = Integer.parseInt(scanner.nextLine()); // 1st pipe debit per hour
  11.         int P2 = Integer.parseInt(scanner.nextLine()); //2nd pipe debit per hour
  12.         float H = Float.parseFloat(scanner.nextLine()); // worker missing hours
  13.  
  14.         double currentV = P1*H + P2*H;
  15.  
  16.         if (V >= currentV) {
  17.             double percent = (currentV / V) * 100;
  18.             double percentP1 = ((P1*H) / currentV) * 100;
  19.             double percentP2 = ((P2*H) / currentV) * 100;
  20.             System.out.printf("The pool is %.0f%% full. Pipe 1: %.0f%%. Pipe 2: %.0f%%.", Math.floor(percent), Math.floor(percentP1), Math.floor(percentP2));
  21.         } else if (V < currentV){
  22.             double overflow = currentV - V;
  23.             System.out.printf("For %.1f hours the pool overflows with %.1f liters.", H, overflow);
  24.         }
  25.  
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement