Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.net.Inet4Address;
- import java.util.Scanner;
- public class PipesInPool {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int poolVolume = Integer.parseInt(scanner.nextLine());
- int p1FlowRate = Integer.parseInt(scanner.nextLine());
- int p2FlowRate = Integer.parseInt(scanner.nextLine());
- double hours = Double.parseDouble(scanner.nextLine());
- //Обемът напълнена вода в басейна (тръба1 й х дебитът ѝ) + (тръба2 х дебитът ѝ)
- double fillVolume = (p1FlowRate * hours) + (p2FlowRate * hours);
- //Обемът напълнена вода, изразен в проценти
- double fillPercentage = (fillVolume / poolVolume) * 100;
- if (poolVolume >= fillVolume) {
- // Колко процента е допринесла тръба1: тръба1 х дебитът ѝ,
- // разделено на обемът напълнена вода и умножено по 100, за да се изрази в проценти:
- double p1Percentage = ((p1FlowRate * hours) / fillVolume) * 100;
- // аналогично за тръба2:
- double p2Percentage = ((p2FlowRate * hours) / fillVolume) * 100;
- System.out.printf("The pool is %.2f%% full. Pipe 1: %.2f%%. Pipe 2: %.2f%%.",
- fillPercentage, p1Percentage, p2Percentage);
- } else {
- //обемът вода, ако басейнът се е препълнил: разликата между напълнена вода и обема на басейна
- double overflowVolume = fillVolume - poolVolume;
- System.out.printf("For %.2f hours the pool overflows with %.2f liters.", hours, overflowVolume);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement