Advertisement
desislava_topuzakova

03. Vacation

Sep 17th, 2021
1,232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.20 KB | None | 0 0
  1. package BasicSyntaxCondLoops_Exercise;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Vacation_03 {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.         int countPeople = Integer.parseInt(scanner.nextLine()); //броят на хората
  9.         String groupType = scanner.nextLine(); //"Students", "Business", "Regular"
  10.         String dayOfWeek = scanner.nextLine(); //"Friday", "Saturday", "Sunday"
  11.  
  12.  
  13.         //крайна цена = броя на хората * цена за 1 нощувка (таблица)
  14.         double pricePerNight = 0;
  15.         switch (dayOfWeek) {
  16.             case "Friday":
  17.                 //проверка за типа на групата
  18.                 switch (groupType) {
  19.                     case "Students":
  20.                         pricePerNight = 8.45;
  21.                         break;
  22.                     case "Business":
  23.                         pricePerNight = 10.90;
  24.                         break;
  25.                     case "Regular":
  26.                         pricePerNight = 15;
  27.                         break;
  28.                 }
  29.                 break;
  30.             case "Saturday":
  31.                 //проверка за типа на групата
  32.                 switch (groupType) {
  33.                     case "Students":
  34.                         pricePerNight = 9.80;
  35.                         break;
  36.                     case "Business":
  37.                         pricePerNight = 15.60;
  38.                         break;
  39.                     case "Regular":
  40.                         pricePerNight = 20;
  41.                         break;
  42.                 }
  43.                 break;
  44.             case "Sunday":
  45.                 //проверка за типа на групата
  46.                 switch (groupType) {
  47.                     case "Students":
  48.                         pricePerNight = 10.46;
  49.                         break;
  50.                     case "Business":
  51.                         pricePerNight = 16;
  52.                         break;
  53.                     case "Regular":
  54.                         pricePerNight = 22.50;
  55.                         break;
  56.                 }
  57.                 break;
  58.         }
  59.  
  60.         double totalPrice = pricePerNight * countPeople;
  61.  
  62.         //ОТСТЪПКИ
  63.         //•   Students – if the group is bigger than or equal to 30 people you should reduce the total price by 15%
  64.         if (groupType.equals("Students") && countPeople >= 30) {
  65.             totalPrice = totalPrice - 0.15 * totalPrice; //0.85 * totalPrice;   or  totalPrice *= 0.85
  66.         }
  67.         //•   Business – if the group is bigger than or equal to 100 people 10 of them can stay for free.
  68.         else if (groupType.equals("Business") && countPeople >= 100) {
  69.             totalPrice = totalPrice - 10 * pricePerNight;
  70.         }
  71.         //•   Regular – if the group is bigger than or equal 10 and less than or equal to 20 reduce the total price by 5%
  72.         else if (groupType.equals("Regular") && countPeople >= 10 && countPeople <= 20) {
  73.             totalPrice = totalPrice - 0.05 * totalPrice; //0.95 * totalPrice;  or totalPrice *= 0.95
  74.         }
  75.  
  76.         System.out.printf("Total price: %.2f", totalPrice);
  77.     }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement