Advertisement
musakahero

Untitled

Jul 19th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.68 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.         String H = scanner.nextLine();
  13.         //double H = Double.parseDouble(scanner.nextLine()); // worker missing hours
  14.         double hToDouble = Double.parseDouble(H);
  15.  
  16.         //customvariables
  17.         //double currentV = P1*H + P2*H;
  18.         double currentV = P1*hToDouble + P2*hToDouble;
  19.  
  20.  
  21.         if (V >= currentV) {
  22.             double percent = (currentV / V) * 100;
  23.             /*double percentP1 = ((P1*H) / currentV) * 100;
  24.             double percentP2 = ((P2*H) / currentV) * 100;*/
  25.             double percentP1 = ((P1*hToDouble) / currentV) * 100;
  26.             double percentP2 = ((P2*hToDouble) / currentV) * 100;
  27.             //System.out.println("The pool is " + Math.floor(percent) + "%. Pipe 1: " + Math.floor(percentP1) + "%. Pipe 2: "+Math.floor(percentP2) + "%.");
  28.             System.out.printf("The pool is %.0f%% full. Pipe 1: %.0f%%. Pipe 2: %.0f%%.", Math.floor(percent), Math.floor(percentP1), Math.floor(percentP2));
  29.             //System.out.printf("The pool is %.0f%% full. Pipe 1: %.0f%%. Pipe 2: %.0f%%.", percent, percentP1, percentP2);
  30.  
  31.         } else if (V < currentV){
  32.             double overflow = currentV - V;
  33.             System.out.printf("For %s hours the pool overflows with %.1f liters.", H, overflow);
  34.         }
  35.  
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement