Advertisement
borkins

Exam 26-Mar-2016 - 02. Pool Pipes

May 14th, 2017
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.33 KB | None | 0 0
  1. /**
  2.  * Project: Exam_26_March_2016 - created by borkins on 2017-05-14.
  3.  */
  4.  
  5. import java.text.DecimalFormat;
  6. import java.util.Scanner;
  7.  
  8. public class _02_PoolPipes
  9. {
  10.     public static void main(String[] args)
  11.     {
  12.         Scanner console = new Scanner(System.in);
  13.         DecimalFormat decFormat = new DecimalFormat("0.##");
  14.    
  15.         int volumePool = Integer.parseInt(console.nextLine());
  16.         int flowPipe1 = Integer.parseInt(console.nextLine());
  17.         int flowPipe2 = Integer.parseInt(console.nextLine());
  18.         double hours = Double.parseDouble(console.nextLine());
  19.    
  20.         double totalLiters = (flowPipe1 + flowPipe2) * hours;
  21.    
  22.         if (volumePool >= (int) totalLiters)
  23.         {
  24.             double totalPipe1 = flowPipe1 * hours * 100 / totalLiters;
  25.             double totalPipe2 = flowPipe2 * hours * 100 / totalLiters;
  26.        
  27.             System.out.printf("The pool is %d%% full. Pipe 1: %d%%. Pipe 2: %d%%.",
  28.                               (int) (totalLiters * 100 / volumePool),
  29.                               (int) totalPipe1, (int) totalPipe2);
  30.         } else {
  31.             System.out.printf("For %s hours the pool overflows with %s liters.",
  32.                               decFormat.format(hours),
  33.                               decFormat.format(totalLiters - volumePool));
  34.         }
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement