Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package pr101;
- import java.text.DecimalFormat;
- import java.util.Scanner;
- public class Pipes {
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- int v = Integer.valueOf(input.nextLine());
- int pOne = Integer.valueOf(input.nextLine());
- int pTwo = Integer.valueOf(input.nextLine());
- double h = Double.valueOf(input.nextLine());
- double pOneFullForH = (double)pOne * h;
- double pTwoFullForH = (double)pTwo * h;
- double percentsPoolFull = ((pOneFullForH + pTwoFullForH) / v) * 100;
- double percntsPipeOne = Math.floor((pOneFullForH / (pOneFullForH + pTwoFullForH)) * 100);
- double percntsPipeTwo = Math.floor((pTwoFullForH / (pOneFullForH + pTwoFullForH)) * 100);
- if ((pOneFullForH + pTwoFullForH) <= v)
- {
- System.out.printf("The pool is %d%% full. Pipe 1: %d%%. Pipe 2: %d%%.%n", (int)percentsPoolFull, (int)percntsPipeOne, (int)percntsPipeTwo);
- }
- else
- {
- double overFlows = Math.abs(v - (pOneFullForH + pTwoFullForH));
- DecimalFormat df = new DecimalFormat("0.#########");
- System.out.printf("For %s hours the pool overflows with %s liters.", df.format(h), df.format(overFlows));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement