Advertisement
A_Marinov

Untitled

May 8th, 2020
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.13 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class PipesInPool {
  4.     public static void main(String[] args) {
  5.         Scanner scan = new Scanner(System.in);
  6.         int poolArea = Integer.parseInt(scan.nextLine());
  7.         int pipeOne = Integer.parseInt(scan.nextLine());
  8.         int pipeTwo = Integer.parseInt(scan.nextLine());
  9.         double hours = Double.parseDouble(scan.nextLine());
  10.         char percentage = '%';
  11.         double pipeOneFills = pipeOne * hours;
  12.         double pipeTwoFills = pipeTwo * hours;
  13.         double totalFills = pipeOneFills + pipeTwoFills;
  14.         double percentPipeOne = pipeOneFills * 100 / totalFills;
  15.         double percentPipeTwo = pipeTwoFills * 100 / totalFills;
  16.  
  17.         if (totalFills <= poolArea) {
  18.             double pp = totalFills * 100 / poolArea;
  19.             System.out.printf("The pool is %.2f%c full. Pipe 1: %.2f%c. Pipe 2: %.2f%c.", pp, percentage, percentPipeOne, percentage, percentPipeTwo, percentage);
  20.  
  21.         } else {
  22.             double total = totalFills - poolArea;
  23.             System.out.printf("For %.2f hours the pool overflows with %.2f liters.", hours, total);
  24.         }
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement