Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class ComputerRoom {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- // Read the input from the console
- String month = scanner.nextLine().toLowerCase();
- int hours = scanner.nextInt();
- int people = scanner.nextInt();
- String time = scanner.nextLine().toLowerCase();
- // Declare and initialize the price per person per hour
- double price = 0.0;
- // Use a switch statement to assign the price according to the month and time
- switch (month) {
- case "march":
- case "april":
- case "may":
- if (time.equals("day")) {
- price = 10.50;
- } else if (time.equals("night")) {
- price = 8.40;
- }
- break;
- case "june":
- case "july":
- case "august":
- if (time.equals("day")) {
- price = 12.60;
- } else if (time.equals("night")) {
- price = 10.20;
- }
- break;
- }
- // Apply the discounts if applicable
- if (people >= 4) {
- // 10% discount for groups of four or more
- price *= 0.9;
- }
- if (hours >= 5) {
- // 50% discount for 5 or more hours spent
- price *= 0.5;
- }
- // Calculate the total cost of the visit
- double total = price * hours * people;
- // Print the output in the required format
- System.out.printf("Price per person for one hour: %.2f%n", price);
- System.out.printf("Total cost of the visit: %.2f%n", total);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement