Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.02 KB | None | 0 0
  1. import java.text.DecimalFormat;
  2. import java.util.Scanner;
  3.  
  4. public class poll {
  5.     public static void main(String[] args) {
  6.         Scanner scanner = new Scanner(System.in);
  7.  
  8.         int v = Integer.parseInt(scanner.nextLine());
  9.         int p1 = Integer.parseInt(scanner.nextLine());
  10.         int p2 = Integer.parseInt(scanner.nextLine());
  11.         double hours = Double.parseDouble(scanner.nextLine());
  12.  
  13.         DecimalFormat df = new DecimalFormat("#.###");
  14.  
  15.         double water = (p1 + p2) * hours;
  16.         double procentWater = (water / v) * 100;
  17.         double procentp1 = (p1 * hours) / water * 100;
  18.         double procentp2 = (p2 * hours) / water * 100;
  19.  
  20.         if (water <= v) {
  21.             System.out.printf("The pool is %d%% full. Pipe 1: %d%%. Pipe 2: %d%%.",
  22.                     (int) procentWater, (int) procentp1, (int) procentp2);
  23.         }else {
  24.             System.out.printf("For %s hours the pool overflows with %s liters. ",
  25.                     df.format(hours),water - v);
  26.         }
  27.  
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement