galinyotsev123

ProgBasicsJavaBook4.2ComplexConditions05Hotel

Jan 21st, 2019
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class E05HotelRoom {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6. String month = scanner.nextLine();
  7. int nights = Integer.parseInt(scanner.nextLine());
  8. double priceApartment = 0.00;
  9. double priceStudio = 0.00;
  10. double totalApartment = 00.00;
  11. double totalStudio = 00.00;
  12. switch (month) {
  13. case "May":
  14. case "October":
  15. priceApartment = 65;
  16. priceStudio = 50;
  17. if (nights > 7 && nights <= 14) {
  18. totalApartment = priceApartment * nights;
  19. totalStudio = priceStudio * nights - priceStudio * nights * 0.05;
  20. } else if (nights > 14) {
  21. totalApartment = priceApartment * nights - priceApartment * nights * 0.10;
  22. totalStudio = priceStudio * nights - priceStudio * nights * 0.30;
  23. } else {
  24. totalApartment = priceApartment * nights;
  25. totalStudio = priceStudio * nights;
  26. }
  27. break;
  28. case "June":
  29. case "September":
  30. priceApartment = 68.70;
  31. priceStudio = 75.20;
  32. if (nights > 14) {
  33. totalApartment = priceApartment * nights - priceApartment * nights * 0.10;
  34. totalStudio = priceStudio * nights - priceStudio * nights * 0.20;
  35. } else {
  36. totalApartment = priceApartment * nights;
  37. totalStudio = priceStudio * nights;
  38. }
  39. break;
  40. case "July":
  41. case "August":
  42. priceApartment = 77;
  43. priceStudio = 76;
  44. if (nights > 14) {
  45. totalApartment = priceApartment * nights - priceApartment * nights * 0.10;
  46. totalStudio = priceStudio * nights;
  47. } else {
  48. totalApartment = priceApartment * nights;
  49. totalStudio = priceStudio * nights;
  50. }
  51. break;
  52. default:
  53. System.out.println("unknown");
  54. break;
  55. }
  56.  
  57.  
  58. System.out.printf("Apartment: %.2f lv.%n", totalApartment);
  59. System.out.printf("Studio: %.2f lv.", totalStudio);
  60.  
  61. }
  62. }
Add Comment
Please, Sign In to add comment