Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.text.DecimalFormat;
- import java.time.LocalDate;
- import java.util.Locale;
- import java.util.Scanner;
- import java.util.regex.Matcher;
- public class Tubes {
- public static void main(String[] args) {
- Locale.setDefault(Locale.ROOT);
- Scanner scan = new Scanner(System.in);
- int volume = Integer.parseInt(scan.nextLine());
- int p1Debit = Integer.parseInt(scan.nextLine());
- int p2Debit = Integer.parseInt(scan.nextLine());
- double hours = Double.parseDouble(scan.nextLine());
- double totalVolume = (p1Debit + p2Debit) * hours;
- if (totalVolume <= volume){
- int p1Percent = (int)((p1Debit * hours) / totalVolume * 100);
- int p2Percent = (int)((p2Debit * hours) / totalVolume * 100);
- int volPercent = (int)(totalVolume / volume * 100);
- System.out.printf("The pool is %d%% full. Pipe 1: %d%%. Pipe 2: %d%%.",
- volPercent, p1Percent, p2Percent);
- }
- else{
- double extraWater = totalVolume - volume;
- String ew = fmt(extraWater);
- DecimalFormat format = new DecimalFormat("#0.##############");
- String h = fmt(hours);
- System.out.printf("For %s hours the pool overflows with %s liters.", h, format.format(extraWater));
- }
- }
- public static String fmt(double d)
- {
- if(d == (long) d)
- return String.format("%d",(long)d);
- else
- return String.format("%s",d);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement