Advertisement
ralitsa_d

Tubes

Jan 25th, 2017
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. import java.text.DecimalFormat;
  2. import java.time.LocalDate;
  3. import java.util.Locale;
  4. import java.util.Scanner;
  5. import java.util.regex.Matcher;
  6.  
  7. public class Tubes {
  8. public static void main(String[] args) {
  9. Locale.setDefault(Locale.ROOT);
  10. Scanner scan = new Scanner(System.in);
  11.  
  12. int volume = Integer.parseInt(scan.nextLine());
  13. int p1Debit = Integer.parseInt(scan.nextLine());
  14. int p2Debit = Integer.parseInt(scan.nextLine());
  15. double hours = Double.parseDouble(scan.nextLine());
  16.  
  17. double totalVolume = (p1Debit + p2Debit) * hours;
  18.  
  19. if (totalVolume <= volume){
  20. int p1Percent = (int)((p1Debit * hours) / totalVolume * 100);
  21. int p2Percent = (int)((p2Debit * hours) / totalVolume * 100);
  22.  
  23. int volPercent = (int)(totalVolume / volume * 100);
  24.  
  25. System.out.printf("The pool is %d%% full. Pipe 1: %d%%. Pipe 2: %d%%.",
  26. volPercent, p1Percent, p2Percent);
  27. }
  28. else{
  29. double extraWater = totalVolume - volume;
  30.  
  31. String ew = fmt(extraWater);
  32. DecimalFormat format = new DecimalFormat("#0.##############");
  33. String h = fmt(hours);
  34. System.out.printf("For %s hours the pool overflows with %s liters.", h, format.format(extraWater));
  35. }
  36. }
  37.  
  38. public static String fmt(double d)
  39. {
  40. if(d == (long) d)
  41. return String.format("%d",(long)d);
  42. else
  43. return String.format("%s",d);
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement