/** * Program Name: EF_MovieTickets.java * Purpose: This program calculates the total price of tickets for a group of people based on their age category. * Coder: Essam Fahmy * Date: Mar 14, 2022 */ import java.util.Scanner; public class EF_MovieTickets { public static void main(String[] args) { //Creating Scanner and Variables and Declaring them Scanner input = new Scanner (System.in); int numChild = 0; int numAdult = 0; int numSenior = 0; final double childPrice = 6.50; final double adultPrice = 11.75; final double seniorPrice = 7.75; int totalPeople = 0; double totalPrice = 0; char inputCategory; //Outputting Introduction and Gaining user Input System.out.println("Movie Theatre Admission"); System.out.println("-----------------------\n"); System.out.println("This program will calculate the total admission price to a movie theatre for a group.\n"); System.out.print("How many people are in your group? "); totalPeople = input.nextInt(); System.out.println(); //Clear Buffer input.nextLine(); //For Loop to Gain User Input for Each Person's Age Category for (int i = 1; i <= totalPeople; i++) { //Gaining User Input for Each Person System.out.print("Enter age category for person " + i + " (C for child, A for adult, S for senior): "); inputCategory = input.next().toUpperCase().charAt(0); //Using Switch to Calculate Number of People in Each Category switch(inputCategory) { case 'C': numChild++; break; case 'A': numAdult++; break; case 'S': numSenior++; break; default: System.out.println("Invalid age category. Enter one of 'C', 'A' or 'S'!"); i--; } } //Closing Scanner input.close(); //Calculating and Outputting Total System.out.println("\nYour group consists of " + numChild + " child(ren), " + numAdult + " adult(s) and " + numSenior + " senior(s)."); totalPrice = (numChild * childPrice) + (numAdult * adultPrice) + (numSenior * seniorPrice); System.out.println("The total admission charge for your group is $" + totalPrice); } //end main }//end class