Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Adventure {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in); // правим скенер
- float budget = scanner.nextFloat(); // budget заема стойността от първия ред вкаран в конзолата, който трябва да бъде Float
- String season = scanner.next(); // season заема стойността от втория ред вкаран в конзолата, който е String
- String destination = Destination(budget); // destination заема на метода Destination с подаден параметър budget
- Budget_cost(destination, season, budget); // извикваме метода Budget_cost, като му подаваме параметри destination, season, budget
- }
- public static String Destination(float Budget){ // правим метод Destination, който очаква параметър float Budget и връща String
- if(Budget <= 100 && Budget > 0){ // проверяваме според условието каква трябва да е дестинацията и я връщаме
- return "Bulgaria";
- }
- else if(Budget <= 1000 && Budget > 0){
- return "Balkans";
- }
- else if (Budget > 0){ // ако е било <= 100 или <= 1000 е щяло вече да попадне в тези условия и затова е нужна само тази проверка тук Budget > 0
- return "Europe";
- }
- return "He will stay at home";
- }
- public static void Budget_cost(String destination, String season, float Budget){ // правим метод Budget_cost, който очаква три параметъра, а именно String destination, String season, float Budget
- float moneySpent = 0; // в началото похарчените пари са 0. Проверяваме как са изпълнени условията и според тях moneySpent заема различна стойност и с помощта на placeholder печатаме исканият от нас текст
- if(destination.equals("Bulgaria") && season.equals("summer")){
- moneySpent = (Budget * 30) / 100;
- System.out.println(String.format("Somewhere in %s", destination));
- System.out.println(String.format("camp - %.2f", moneySpent));
- }
- else if(destination.equals("Bulgaria") && season.equals("winter")){
- moneySpent = (Budget * 70) / 100;
- System.out.println(String.format("Somewhere in %s", destination));
- System.out.println(String.format("hotel - %.2f", moneySpent));
- }
- else if(destination.equals("Balkans") && season.equals("summer")){
- moneySpent = (Budget * 40) / 100;
- System.out.println(String.format("Somewhere in %s", destination));
- System.out.println(String.format("camp - %.2f", moneySpent));
- }
- else if(destination.equals("Balkans") && season.equals("winter")){
- moneySpent = (Budget * 80) / 100;
- System.out.println(String.format("Somewhere in %s", destination));
- System.out.println(String.format("hotel - %.2f", moneySpent));
- }
- else if(destination.equals("Europe")){
- moneySpent = (Budget * 90) / 100;
- System.out.println(String.format("Somewhere in %s", destination));
- System.out.println(String.format("hotel - %.2f", moneySpent));
- }
- }
- }
Add Comment
Please, Sign In to add comment