Advertisement
veronikaaa86

Pool

Oct 17th, 2017
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.09 KB | None | 0 0
  1. package Exam17September2017;
  2.  
  3. import java.text.DecimalFormat;
  4. import java.util.Scanner;
  5.  
  6. public class Demo {
  7.     public static void main(String[] args) {
  8.         Scanner scanner = new Scanner(System.in);
  9.         DecimalFormat df = new DecimalFormat("#.##");
  10.  
  11.         double V = Double.parseDouble(scanner.nextLine());
  12.         double P1 = Double.parseDouble(scanner.nextLine());
  13.         double P2 = Double.parseDouble(scanner.nextLine());
  14.         double H = Double.parseDouble(scanner.nextLine());
  15.  
  16.         double p1 = H * P1;
  17.         double p2 = H * P2;
  18.         double obshto = p1 + p2;
  19.  
  20.         if (obshto <= V) {
  21.             double prozent = obshto / (V / 100);
  22.             double prozent1 = p1 / (obshto / 100);
  23.             double prozent2 = p2 / (obshto / 100);
  24.  
  25.             System.out.printf("The pool is %d%% full. Pipe 1: %d%%. Pipe 2: %d%%." ,(int)prozent,(int)prozent1,(int)prozent2);
  26.  
  27.         } else {
  28.             double overflows = obshto - V;
  29.  
  30.             System.out.printf("For %s hours the pool overflows with %.1f liters." ,df.format(H),overflows);
  31.         }
  32.     }
  33.  
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement