Advertisement
ivanmitkoff

Untitled

May 31st, 2019
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.89 KB | None | 0 0
  1. import java.net.Inet4Address;
  2. import java.util.Scanner;
  3.  
  4. public class PipesInPool {
  5.     public static void main(String[] args) {
  6.         Scanner scanner = new Scanner(System.in);
  7.  
  8.         int poolVolume = Integer.parseInt(scanner.nextLine());
  9.         int p1FlowRate = Integer.parseInt(scanner.nextLine());
  10.         int p2FlowRate = Integer.parseInt(scanner.nextLine());
  11.         double hours = Double.parseDouble(scanner.nextLine());
  12.        
  13.         //Обемът напълнена вода в басейна (тръба1 й х дебитът ѝ) + (тръба2 х дебитът ѝ)
  14.         double fillVolume = (p1FlowRate * hours) + (p2FlowRate * hours);
  15.        
  16.         //Обемът напълнена вода, изразен в проценти
  17.         double fillPercentage = (fillVolume / poolVolume) * 100;
  18.  
  19.         if (poolVolume >= fillVolume) {
  20.             // Колко процента е допринесла тръба1: тръба1 х дебитът ѝ,
  21.             // разделено на обемът напълнена вода и умножено по 100, за да се изрази в проценти:
  22.             double p1Percentage = ((p1FlowRate * hours) / fillVolume) * 100;
  23.            
  24.             // аналогично за тръба2:
  25.             double p2Percentage = ((p2FlowRate * hours) / fillVolume) * 100;
  26.             System.out.printf("The pool is %.2f%% full. Pipe 1: %.2f%%. Pipe 2: %.2f%%.",
  27.                     fillPercentage, p1Percentage, p2Percentage);
  28.         } else {
  29.             //обемът вода, ако басейнът се е препълнил: разликата между напълнена вода и обема на басейна
  30.             double overflowVolume = fillVolume - poolVolume;
  31.             System.out.printf("For %.2f hours the pool overflows with %.2f liters.", hours, overflowVolume);
  32.         }
  33.  
  34.  
  35.  
  36.  
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement