Advertisement
Guest User

Untitled

a guest
Mar 6th, 2017
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.93 KB | None | 0 0
  1. import java.text.DecimalFormat;
  2. import java.util.Scanner;
  3.  
  4. public class Ex02PipesInPool {
  5.     public static void main(String[] args) {
  6.         Scanner scanner = new Scanner(System.in);
  7.         double V = (double) Integer.parseInt(scanner.nextLine());
  8.         double P1 = (double) Integer.parseInt(scanner.nextLine());
  9.         double P2 = (double) Integer.parseInt(scanner.nextLine());
  10.         double hours = Double.parseDouble(scanner.nextLine());
  11.  
  12.         double volume = (P1 + P2) * hours;
  13.         if (volume <= V) {
  14.             System.out.printf("The pool is %d%% full. Pipe 1: %d%%. Pipe 2: %d%%.%n",
  15.                     (int) (volume / V * 100d), (int) (P1 * 100d / (P1 + P2)), (int) (P2 * 100d / (P1 + P2)));
  16.         } else {
  17.             DecimalFormat df = new DecimalFormat("0.##");
  18.             System.out.printf("For %s hours the pool overflows with %s liters.%n", df.format(hours), df.format(volume-V));
  19.         }
  20.     }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement