Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class poolPipes {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- //inputvariables
- int V = Integer.parseInt(scanner.nextLine()); //volume of pool in litres
- int P1 = Integer.parseInt(scanner.nextLine()); // 1st pipe debit per hour
- int P2 = Integer.parseInt(scanner.nextLine()); //2nd pipe debit per hour
- float H = Float.parseFloat(scanner.nextLine()); // worker missing hours
- double currentV = P1*H + P2*H;
- if (V >= currentV) {
- double percent = (currentV / V) * 100;
- double percentP1 = ((P1*H) / currentV) * 100;
- double percentP2 = ((P2*H) / currentV) * 100;
- System.out.printf("The pool is %.0f%% full. Pipe 1: %.0f%%. Pipe 2: %.0f%%.", Math.floor(percent), Math.floor(percentP1), Math.floor(percentP2));
- } else if (V < currentV){
- double overflow = currentV - V;
- System.out.printf("For %.1f hours the pool overflows with %.1f liters.", H, overflow);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement