Advertisement
atanasovetr

Pipes

Jan 16th, 2020
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.15 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Pipes {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in); // правим скенер
  6. int V = scanner.nextInt(); // V заема стойността от първия ред вкаран в конзолата, който трябва да бъде Int
  7. int P1 = scanner.nextInt(); // P1 заема стойността от втория ред вкаран в конзолата, който трябва да бъде Int
  8. int P2 = scanner.nextInt(); // P2 заема стойността от третия ред вкаран в конзолата, който трябва да бъде Int
  9. float H = scanner.nextFloat(); // H заема стойността от четвъртия ред вкаран в конзолата, който трябва да бъде Float
  10.  
  11.  
  12. if (Pool_condition(V,P1,P2,H)!=0) { // ако стойността на метода е различна от нула да принтира дадените по условия неща, използваме %% защото % е специален символ
  13. System.out.printf("The pool is %d%% full. Pipe 1: %d%%. Pipe2: %.2f%% .",
  14. Pool_condition(V, P1, P2, H),
  15. Pipe1Percentage(P1, P2, H),
  16. Pipe2Percentage(P1, P2, H));
  17. }
  18. else{// ако е стойността на метода е 0 принтираме с колко литра е прелял басейна
  19. System.out.printf("For H hours the pool overflows with %.2f liters.", (P1+P2)*H - V);
  20. }
  21. }
  22. public static Integer Pool_condition(int volume, int pipe1, int pipe2, float hours){ // метод който очаква като параметри int volume, int pipe1, int pipe2, float hours. Той връща колко е пълен басейна като Integer
  23. float last_volume =(float) (pipe1 + pipe2) * hours; // смятаме колко литра вземат тръбите
  24. if (last_volume < volume) { // проверяваме дали източената вода е по-малко от цялата
  25. return (int)(last_volume / volume) * 100;
  26. }
  27. else{ // ако е повече или равна връщаме 0 като стойност
  28. return 0;
  29. }
  30. }
  31. public static Integer Pipe1Percentage(int pipe1, int pipe2, float hours){// Метод, приема 3 стойности: int pipe1, int pipe2, float hours и пресмята процентите на първата тръба
  32. float debit_total = (pipe1 + pipe2) * hours;
  33. float percentage = (pipe1*hours / debit_total) * 100;
  34. return (int)percentage;
  35.  
  36. }
  37. public static Integer Pipe2Percentage(int pipe1, int pipe2, float hours){// Метод, приема 3 стойности: int pipe1, int pipe2, float hours и пресмята процентите на втората тръба
  38. float debit_total = (pipe1 + pipe2) * hours;
  39. float percentage = (pipe2*hours / debit_total) * 100;
  40. return (int)percentage;
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement