In: Computer Science
This program is broken down into phases for your convenience only. Please turn in only the final phase. Before turning in your program, please make sure that it does something reasonable if the user enters a negative number the first time.
Phase I: Write a program for a theater that will keep track of how many people in each of 5 age categories attended a particular movie. Use the 5 age categories listed below in the sample screen output. The user will enter a number of ages, entering a negative number when there are no more ages to enter. Your program will then report on how many people in each age group attended. Sample screen output:
Enter age of attendee (-1 to quit): 34 Enter age of attendee (-1 to quit): 16 Enter age of attendee (-1 to quit): 68 Enter age of attendee (-1 to quit): 53 Enter age of attendee (-1 to quit): 39 Enter age of attendee (-1 to quit): 23 Enter age of attendee (-1 to quit): 21 Enter age of attendee (-1 to quit): -1 age 0 to 18: 1 age 19 to 30: 2 age 31 to 40: 2 age 41 to 60: 1 over 60: 1 |
Phase II: Modify your program so that, in addition
to the report that the program currently produces, it also gives
the average age of the people in attendance, the age of the oldest
person in attendance, and the age of the youngest person in
attendance. Sample screen output:
Enter age of attendee (-1 to quit): 34 Enter age of attendee (-1 to quit): 16 Enter age of attendee (-1 to quit): 68 Enter age of attendee (-1 to quit): 53 Enter age of attendee (-1 to quit): 39 Enter age of attendee (-1 to quit): 23 Enter age of attendee (-1 to quit): 21 Enter age of attendee (-1 to quit): -1 age 0 to 18: 1 age 19 to 30: 2 age 31 to 40: 2 age 41 to 60: 1 over 60: 1 The average age was 36. The youngest person in attendance was 16. The oldest person in attendance was 68. |
Phase III: Modify your program so that it also asks each attendee for a theater concession stand purchase. The attendee must make a selection based on the following choices …
1 - Soft Drink (such as Coca Cola, ICCEE, Mineral Water etc...)
2 - Popcorn
3 - Nachos
4 - Soft drink & Popcorn
5 - Soft drink & Nachos
6 - Organic and Gluten-free snacks
7 – None
The program output should now also provide a theater concession stand sales summary with a count of each category purchased.
Note: Include a validation routine to ensure that a correct choice is input for each attendee.
Check the sample screen output below for the final formatted display of theater statistics.
========================== THEATER STATS PROGRAM ========================== Movie theater snacks available for purchase ========================================== 1 - Soft Drink (such as Coca Cola, ICCEE, Mineral Water etc...) 2 - Popcorn 3 - Nachos 4 - Soft drink & Popcorn 5 - Soft drink & Nachos 6 - Organic and Gluten-free snacks 7 - None ========================================== Enter age of attendee (-1 to quit): 34 Movie theater snack purchased. (Select items 1 - 7):4 -------------------------- Enter age of attendee (-1 to quit): 16 Movie theater snack purchased. (Select items 1 - 7):5 -------------------------- Enter age of attendee (-1 to quit): 68 Movie theater snack purchased. (Select items 1 - 7):12 Invalid selection, please choose from 1 - 7 Movie theater snack purchased. (Select items 1 - 7):6 -------------------------- Enter age of attendee (-1 to quit): 53 Movie theater snack purchased. (Select items 1 - 7):6 -------------------------- Enter age of attendee (-1 to quit): 39 Movie theater snack purchased. (Select items 1 - 7):1 -------------------------- Enter age of attendee (-1 to quit): 23 Movie theater snack purchased. (Select items 1 - 7):2 -------------------------- Enter age of attendee (-1 to quit): 21 Movie theater snack purchased. (Select items 1 - 7):3 -------------------------- Enter age of attendee (-1 to quit): 21 Movie theater snack purchased. (Select items 1 - 7):4 -------------------------- Enter age of attendee (-1 to quit): -1 ================================== THEATER STATS PROGRAM RESULTS ================================== age 0 to 18: 1 age 19 to 30: 3 age 31 to 40: 2 age 41 to 60: 1 over 60: 1 The average age was 34 The youngest person in attendance was 16 The oldest person in attendance was 68 Theater Concession Stand sales ================================== Soft Drink (such as Coca Cola, ICCEE, Mineral Water etc.): 1 Popcorn: 1 Nachos: 1 Soft drink & Popcorn: 2 Soft drink & Nachos: 1 Organic and Gluten-free snacks: 2 Process returned 0 (0x0) execution time : 169.589 s Press any key to continue. |
PLEASE GIVE IT A THUMBS UP, I SERIOUSLY NEED ONE, IF YOU NEED ANY MODIFICATION THEN LET ME KNOW, I WILL DO IT FOR YOU
import java.lang.*;
import java.util.Scanner;
class Theater {
public static void main(String args[]) {
//variables
int people = 0, age = 0, sum_age = 0;
int age0_18 = 0, age19_30 = 0, age31_40 = 0, age41_60 = 0, age60 = 0;
int young = 1000, old = 0;
int popcorn = 0, soda = 0, both = 0;
char food;
//object for obtaining the input of the primitive types
Scanner sc = new Scanner(System.in);
while (true) {
//prompt for age
System.out.println("Enter age of attendee (negative number to quit): ");
age = Integer.parseInt(sc.next());
//if age is negative exits the loop
if (age < 0) break; else {
//counting attendance
people++;
//calculating sum of age
sum_age = age + sum_age;
//age b/w 0-18
if (age >= 0 && age <= 18) age0_18++;
//age b/w 19-30
else if (age >= 19 && age <= 30) age19_30++;
//age b/w 31-40
else if (age >= 31 && age <= 40) age31_40++;
//age b/w 41-60
else if (age >= 41 && age <= 60) age41_60++;
//age over 60
else age60++;
}
//finding oldest attendee
if (age > old) old = age;
//finding youngest attendee
if (age < young) young = age;
System.out.println(
"Enter food preference ('p' for popcorn, 's' for soda, 'b' for both): "
);
food = sc.next().charAt(0);
//popcorn
if (food == 'p') popcorn++;
//soda
else if (food == 's') soda++;
//both
else both++;
}
//if the user enters a negative number the first time
if (people == 0) {
System.out.println("Attendance is ZERO");
System.exit(0);
}
System.out.println("age 0 to 18: " + age0_18);
System.out.println("age 19 to 30: " + age19_30);
System.out.println("age 31 to 40: " + age31_40);
System.out.println("age 41 to 60: " + age41_60);
System.out.println("over 60 : " + age60);
System.out.println("");
System.out.println("food preference popcorn:" + popcorn);
System.out.println("food preference soda :" + soda);
System.out.println("food preference both :" + both);
System.out.println("The average age was :" + (sum_age / people));
System.out.println("The youngest person in the attendance was: " + young);
System.out.println("The oldest person in the attendance was : " + old);
}
}