Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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

ID: 3675105 • Letter: T

Question

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:


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:

Phase III: Modify your program so that it also asks for the gender of each attendee. Your program should then break the attendance down by gender as well as by age. 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  

Explanation / Answer

1) Theater1.java

package org.students;

import java.util.Scanner;

public class Theater1 {

   public static void main(String[] args) {
       int age1 = 0;
       int age2 = 0;
       int age3 = 0;
       int age4 = 0;
       int age5 = 0;
       while (true) {
           System.out.print("Enter the age of the attendee(-1 to quit):");
           Scanner sc = new Scanner(System.in);
           int age = sc.nextInt();
           if (age > 0) {
               if (age > 0 && age <= 18) {
                   age1++;
               } else if (age >= 19 && age <= 30) {
                   age2++;
               } else if (age >= 31 && age <= 40) {
                   age3++;
               } else if (age >= 41 && age <= 60) {
                   age4++;
               } else if (age > 60) {
                   age5++;
               }
               continue;
           } else {
               break;
           }
       }
       System.out.println(" ");
       System.out.println(" age 0 to 18: " + age1);
       System.out.println(" age 19 to 30:" + age2);
       System.out.println(" age 31 to 40:" + age3);
       System.out.println(" age 41 to 60:" + age4);
       System.out.println(" over 60 :" + age5);
   }

}

--------------------------------------------

2) Theater2.java

package org.students;

import java.util.ArrayList;
import java.util.Scanner;

public class Theater2 {

   public static void main(String[] args) {
       int age1 = 0;
       int age2 = 0;
       int age3 = 0;
       int age4 = 0;
       int age5 = 0;
       int count = 0;
       int total = 0;
       int smallest = 0;
       int biggest = 0;
       int smallest1 = 0;
       while (true) {
           System.out.print("Enter the age of the attendee(-1 to quit):");
           Scanner sc = new Scanner(System.in);
           int age = sc.nextInt();
           if (age > 0) {
               count++;
               total = total + age;
               if (age > biggest) {
                   biggest = age;

               }

               if (age > 0 && age <= 18) {
                   age1++;
               } else if (age >= 19 && age <= 30) {
                   age2++;
               } else if (age >= 31 && age <= 40) {
                   age3++;
               } else if (age >= 41 && age <= 60) {
                   age4++;
               } else if (age > 60) {
                   age5++;
               }
               continue;
           } else {
               break;
           }
       }
       System.out.println(" ");
       System.out.println(" age 0 to 18: " + age1);
       System.out.println(" age 19 to 30:" + age2);
       System.out.println(" age 31 to 40:" + age3);
       System.out.println(" age 41 to 60:" + age4);
       System.out.println(" over 60 :" + age5);
       System.out.println("The average age was::" + total / count);
       System.out.println("The Eldest Among all the people is:" + biggest);
      
   }

}

--------------------------------------------------

3) Theater3.java

package org.students;

import java.util.ArrayList;
import java.util.Scanner;

public class Theater3 {

   public static void main(String[] args) {
       int age1 = 0;
       int age2 = 0;
       int age3 = 0;
       int age4 = 0;
       int age5 = 0;
       int count = 0;
       int total = 0;
       int smallest = 0;
       int biggest = 0;
       int smallest1 = 0;
       int male = 0;
       int female = 0;
       while (true) {
           System.out.print("Enter the age of the attendee(-1 to quit):");
           Scanner sc = new Scanner(System.in);
           int age = sc.nextInt();

           if (age > 0) {
               System.out.print("Enter Gender(M or F):");
               char ch = sc.next().charAt(0);
               count++;
               total = total + age;
               if (age > biggest) {
                   biggest = age;

               }

               if (ch == 'M' || ch == 'm') {
                   male++;
               } else {
                   female++;
               }

               if (age > 0 && age <= 18) {
                   age1++;
               } else if (age >= 19 && age <= 30) {
                   age2++;
               } else if (age >= 31 && age <= 40) {
                   age3++;
               } else if (age >= 41 && age <= 60) {
                   age4++;
               } else if (age > 60) {
                   age5++;
               }
               continue;
           } else {
               break;
           }
       }
       System.out.println(" ");
       System.out.println(" age 0 to 18: " + age1);
       System.out.println(" age 19 to 30:" + age2);
       System.out.println(" age 31 to 40:" + age3);
       System.out.println(" age 41 to 60:" + age4);
       System.out.println(" over 60 :" + age5);
       System.out.println("");
       System.out.println("Male:" + male);
       System.out.println("Female" + female);
       System.out.println();
       System.out.println("The average age was::" + total / count);
       System.out.println("The Eldest Among all the people is:" + biggest);

   }

}

-----------------------------------------------------------------------------------------

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote