Question

In: Computer Science

This program is broken down into phases for your convenience only. Please turn in only the...

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. 

Solutions

Expert Solution

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);
  }
}

Related Solutions

The manipulation of the LIBOR can be broken down into three phases. What were these and...
The manipulation of the LIBOR can be broken down into three phases. What were these and how did they differ in terms of motivation and moral justification?
You are managing a large construction project that’s been broken down into sub-projects (or phases). Each...
You are managing a large construction project that’s been broken down into sub-projects (or phases). Each of these sub-projects is scheduled to take between three and six months to complete. At the end of each subproject, you plan to go through the closing processes and document lessons learned. Which of the following BEST describes what you must do at the beginning of each sub-project or phase? a. Make sure you don’t involve the team, to avoid introducing too much project...
Please give a brief yet thorough explanation of the physiology of the lungs broken down short...
Please give a brief yet thorough explanation of the physiology of the lungs broken down short enough and in bullets for a powerpoint.
in c++ please In this program you are going to have several files to turn in...
in c++ please In this program you are going to have several files to turn in (NOT JUST ONE!!) hangman.h – this is your header file – I will give you a partially complete header file to start with. hangman.cpp – this is your source file that contains your main function functions.cpp – this is your source file that contains all your other functions wordBank.txt – this is the file with words for the game to use.  You should put 10...
WRITE CODE IN JAVA it is now your turn to create a program of your choosing....
WRITE CODE IN JAVA it is now your turn to create a program of your choosing. If you are not sure where to begin, think of a task that you repeat often in your major that would benefit from a program. For example, chemistry unit conversions, finding the area for geometric shapes, etc. You can also create an interactive story that changes based on the user input/decisions. The possibilities are endless. The program must include instructions for the user. Be...
Your friend keeps telling you that fatty acids are broken down to sugar in the body...
Your friend keeps telling you that fatty acids are broken down to sugar in the body and used for energy. You disagree. In a simple explanation of metabolism, tell your friend why this idea is false. (1 point) Vitamin B6 plays many roles in the body, but a very important one ensuring that we aren’t required to eat ALL amino acids directly in the diet. Explain how this works. (2 points)
Write a program to run on your Arduino and PortMaster board that will sequentially turn on...
Write a program to run on your Arduino and PortMaster board that will sequentially turn on and off the LED segments, so it resembles Cylon eyes (https://youtu.be/UajcgzK2shQ). Use the millis() construct shown in lecture rather than delay(). The traverse from one side to the other should take about 1 second.
Problem 1. Complete the table below. Please use the spreadsheet for your convenience and to submit...
Problem 1. Complete the table below. Please use the spreadsheet for your convenience and to submit your responses. Given: total Fixed Costs = $60 (i.e., the fixed cost of $60 does not change with output). The price of the product is $55 Production Schedule for a widget firm Output (Q) Total Fixed Costs (TFC) Total Variable Cost               (VC) Total Cost (TC) Average Fixed Cost (AFC) Average Variable Cost (AVC) Average Total Costs (ATC) Total Revenue (TR) Profit 0 0 1...
The periodic table is broken down into rows and blocks such as the s, p, d...
The periodic table is broken down into rows and blocks such as the s, p, d and f blocks. Each block has different properties associated with them. It has been hypothesized that we could eventually reach a “g” block if enough elements were created.Hypothesize what kinds of properties a “g” block element would have. Would it be stable? Radioactive? What would its radius be like? Please explain your reasoning in 200 - 250 words.
The Investment Management Process is broken down into 3 stages. What are they and what is...
The Investment Management Process is broken down into 3 stages. What are they and what is the most important one?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT