Advertisement
veronikaaa86

Demo

Sep 27th, 2017
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.11 KB | None | 0 0
  1. package Exam26March2016;
  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.             int v = Integer.parseInt(scanner.nextLine());
  10.             int p1 = Integer.parseInt(scanner.nextLine());
  11.             int p2 = Integer.parseInt(scanner.nextLine());
  12.             double h = Double.parseDouble(scanner.nextLine());
  13.  
  14.             double vol1=h*p1;
  15.             double vol2=h*p2;
  16.             double totalvol=vol1+vol2;
  17.             double fullpercent=(totalvol/v)*100;
  18.             double percent1=(vol1/totalvol)*100;
  19.             double percent2=(vol2/totalvol)*100;
  20.             if (totalvol<=v){
  21.                 System.out.printf("The pool is %d%% full. Pipe 1: %d%%. Pipe 2: %d%%.", (int)fullpercent, (int)percent1, (int)percent2);
  22.  
  23.             }
  24.             else {
  25.                 DecimalFormat df = new DecimalFormat("0.##");
  26.                 System.out.printf("For %s hours the pool overflows with %.1f liters.", df.format(h), totalvol-v);
  27.  
  28.             }
  29.         }
  30.  
  31.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement