Advertisement
CR7CR7

Computer-Hall

Apr 29th, 2023
889
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.79 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class ComputerRoom {
  4.  
  5.     public static void main(String[] args) {
  6.         Scanner scanner = new Scanner(System.in);
  7.  
  8.         // Read the input from the console
  9.         String month = scanner.nextLine().toLowerCase();
  10.         int hours = Integer.parseInt(scanner.nextLine());
  11.         int people = Integer.parseInt(scanner.nextLine());
  12.         String time = scanner.nextLine().toLowerCase();
  13.  
  14.         // Declare and initialize the price per person per hour
  15.         double price = 0.0;
  16.  
  17.         // Use a switch statement to assign the price according to the month and time
  18.         switch (month) {
  19.             case "march":
  20.             case "april":
  21.             case "may":
  22.                 if (time.equals("day")) {
  23.                     price = 10.50;
  24.                 } else if (time.equals("night")) {
  25.                     price = 8.40;
  26.                 }
  27.                 break;
  28.             case "june":
  29.             case "july":
  30.             case "august":
  31.                 if (time.equals("day")) {
  32.                     price = 12.60;
  33.                 } else if (time.equals("night")) {
  34.                     price = 10.20;
  35.                 }
  36.                 break;
  37.         }
  38.  
  39.         // Apply the discounts if applicable
  40.         if (people >= 4) {
  41.             // 10% discount for groups of four or more
  42.             price *= 0.9;
  43.         }
  44.         if (hours >= 5) {
  45.             // 50% discount for 5 or more hours spent
  46.             price *= 0.5;
  47.         }
  48.  
  49.         // Calculate the total cost of the visit
  50.         double total = price * hours * people;
  51.  
  52.         // Print the output in the required format
  53.         System.out.printf("Price per person for one hour: %.2f%n", price);
  54.         System.out.printf("Total cost of the visit: %.2f%n", total);
  55.     }
  56. }
  57.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement