atanasovetr

Adventure

Jan 16th, 2020
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.61 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Adventure {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in); // правим скенер
  6. float budget = scanner.nextFloat(); // budget заема стойността от първия ред вкаран в конзолата, който трябва да бъде Float
  7. String season = scanner.next(); // season заема стойността от втория ред вкаран в конзолата, който е String
  8. String destination = Destination(budget); // destination заема на метода Destination с подаден параметър budget
  9. Budget_cost(destination, season, budget); // извикваме метода Budget_cost, като му подаваме параметри destination, season, budget
  10.  
  11. }
  12. public static String Destination(float Budget){ // правим метод Destination, който очаква параметър float Budget и връща String
  13. if(Budget <= 100 && Budget > 0){ // проверяваме според условието каква трябва да е дестинацията и я връщаме
  14. return "Bulgaria";
  15. }
  16. else if(Budget <= 1000 && Budget > 0){
  17. return "Balkans";
  18. }
  19. else if (Budget > 0){ // ако е било <= 100 или <= 1000 е щяло вече да попадне в тези условия и затова е нужна само тази проверка тук Budget > 0
  20. return "Europe";
  21. }
  22. return "He will stay at home";
  23. }
  24. public static void Budget_cost(String destination, String season, float Budget){ // правим метод Budget_cost, който очаква три параметъра, а именно String destination, String season, float Budget
  25. float moneySpent = 0; // в началото похарчените пари са 0. Проверяваме как са изпълнени условията и според тях moneySpent заема различна стойност и с помощта на placeholder печатаме исканият от нас текст
  26. if(destination.equals("Bulgaria") && season.equals("summer")){
  27. moneySpent = (Budget * 30) / 100;
  28. System.out.println(String.format("Somewhere in %s", destination));
  29. System.out.println(String.format("camp - %.2f", moneySpent));
  30. }
  31. else if(destination.equals("Bulgaria") && season.equals("winter")){
  32. moneySpent = (Budget * 70) / 100;
  33. System.out.println(String.format("Somewhere in %s", destination));
  34. System.out.println(String.format("hotel - %.2f", moneySpent));
  35. }
  36. else if(destination.equals("Balkans") && season.equals("summer")){
  37. moneySpent = (Budget * 40) / 100;
  38. System.out.println(String.format("Somewhere in %s", destination));
  39. System.out.println(String.format("camp - %.2f", moneySpent));
  40. }
  41. else if(destination.equals("Balkans") && season.equals("winter")){
  42. moneySpent = (Budget * 80) / 100;
  43. System.out.println(String.format("Somewhere in %s", destination));
  44. System.out.println(String.format("hotel - %.2f", moneySpent));
  45. }
  46. else if(destination.equals("Europe")){
  47. moneySpent = (Budget * 90) / 100;
  48. System.out.println(String.format("Somewhere in %s", destination));
  49. System.out.println(String.format("hotel - %.2f", moneySpent));
  50. }
  51.  
  52.  
  53. }
  54.  
  55.  
  56. }
Add Comment
Please, Sign In to add comment