Advertisement
KeepCoding

Pipes In Pool Exam 26th March 2016

Nov 6th, 2017
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. import java.text.DecimalFormat;
  2. import java.util.Scanner;
  3.  
  4. public class Wat {
  5. public static void main(String[] args) {
  6. Scanner scanner = new Scanner(System.in);
  7. int v = Integer.parseInt(scanner.nextLine());
  8. int p1 = Integer.parseInt(scanner.nextLine());
  9. int p2 = Integer.parseInt(scanner.nextLine());
  10. double h = Double.parseDouble(scanner.nextLine());
  11. double p1h = p1 * h;
  12. double p2h = p2 * h;
  13. DecimalFormat df = new DecimalFormat("#.#####");
  14. if (p1h + p2h > v) {
  15. double overflow = (p1h + p2h) - v;
  16. String answer1 = df.format(h).toString();
  17. System.out.printf("For %s hours the pool overflows with %.01f liters.", answer1, overflow);
  18. } else {
  19. double vp = p1h + p2h;
  20. double percentage1 = Math.floor((p1h / vp) * 100);
  21. double percentage2 = Math.floor((p2h / vp) * 100);
  22. double percentageFull = Math.floor((vp / v) * 100);
  23. String answer1 = df.format(percentageFull).toString();
  24. String answer2 = df.format(percentage1).toString();
  25. String answer3 = df.format(percentage2).toString();
  26. System.out.printf("The pool is %s%% full. Pipe 1: %s%%. Pipe 2: %s%%.", answer1, answer2, answer3);
  27. }
  28. //code ends here
  29. }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement