Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package helper;
- import java.text.DecimalFormat;
- import java.util.Scanner;
- public class Pools {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int v = Integer.parseInt(scanner.nextLine());
- int p1 = Integer.parseInt(scanner.nextLine());
- int p2 = Integer.parseInt(scanner.nextLine());
- double H = Double.parseDouble(scanner.nextLine());
- double pipe1 = p1 * H;
- double pipe2 = p2 * H;
- double total = pipe1 + pipe2;
- double pool = (total / v) * 100;
- double overflows = total - v;
- DecimalFormat format = new DecimalFormat("#.###############");
- if (v>=total) {
- int pip1 = (int) ((pipe1/total)*100);
- int pip2 = (int) ((pipe2/total)*100);
- int fullpool = (int) pool;
- System.out.printf("The pool is %s%% full. Pipe 1: %s%%. Pipe 2: %s%%.", format.format(fullpool)
- , format.format(pip1), format.format(pip2));
- } else {
- System.out.printf("For %s hours the pool overflows with %s liters.", format.format(H), format.format(overflows));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement