Advertisement
Ligh7_of_H3av3n

03.ExcursionCalculator

Oct 15th, 2023
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.89 KB | None | 0 0
  1. package PodgotovkaZaIzpit;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class ExcursionCalculator {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.         // Set initial variables
  10.         int tourists = Integer.parseInt(scanner.nextLine());
  11.         String season = scanner.nextLine();
  12.         double pricePerTourist = 0;
  13.  
  14.         // Calculate pricePerTourist depending on season and tourist number
  15.         if (season.equals("spring")) {
  16.             if (tourists > 5)
  17.             {
  18.                 pricePerTourist = 48;
  19.             }
  20.             else
  21.             {
  22.                 pricePerTourist = 50;
  23.             }
  24.         }
  25.         else if (season.equals("summer")) {
  26.             if (tourists > 5)
  27.             {
  28.                 pricePerTourist = 45;
  29.             }
  30.             else
  31.             {
  32.                 pricePerTourist = 48.50;
  33.             }
  34.         }
  35.         else if (season.equals("autumn")) {
  36.             if (tourists > 5)
  37.             {
  38.                 pricePerTourist = 49.50;
  39.             }
  40.             else
  41.             {
  42.                 pricePerTourist = 60;
  43.             }
  44.         }
  45.         else if (season.equals("winter")) {
  46.             if (tourists > 5)
  47.             {
  48.                 pricePerTourist = 85;
  49.             }
  50.             else
  51.             {
  52.                 pricePerTourist = 86;
  53.             }
  54.         }
  55.  
  56.         double finalPrice = pricePerTourist * tourists;
  57.  
  58.         // Calculate discount/rise of finalPrice depending on the season
  59.         if (season.equals("summer")) {
  60.             finalPrice = finalPrice *.85;
  61.         }
  62.         else if (season.equals("winter")) {
  63.             finalPrice =finalPrice * 1.08;
  64.         }
  65.  
  66.         // Print out finalPrice (:F2 prints out 2 numbers after decimal point, use F1/F3/F4 for different outputs)
  67.         System.out.printf("%f leva.", finalPrice);
  68.     }
  69.     }
  70.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement