MladenKarachanov

PipesInPool

Jan 19th, 2024
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.07 KB | None | 0 0
  1. package ProgrammingBasics2;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class PipesInPool {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.         int v = Integer.parseInt(scanner.nextLine());
  9.         int p1 = Integer.parseInt(scanner.nextLine());
  10.         int p2 = Integer.parseInt(scanner.nextLine());
  11.         double h = Double.parseDouble(scanner.nextLine());
  12.         double fillingWithWater = p1 * h;
  13.         double fillingWithWater2 = p2 * h;
  14.         double all = fillingWithWater + fillingWithWater2;
  15.         double contributed = (all / v) * 100;
  16.         double contributed2 = ((fillingWithWater / all) * 100);
  17.         double contributed3 = ((fillingWithWater2 / all) * 100);
  18.  
  19.         if (all > v) {
  20.             //     double overflow =Math.abs(all-v);
  21.             System.out.printf("For %.2f hours the pool overflows with %.2f liters.", h, Math.abs(all - v));
  22.         } else {
  23.             System.out.printf("The pool is %.2f%% full. Pipe 1: %.2f%%. Pipe 2: %.2f%%.", contributed, contributed2, contributed3);
  24.         }
  25.     }
  26. }
Add Comment
Please, Sign In to add comment