Question

public class MovieAudience {    public static void main(String[] args) {        // input (hard-coded)...

public class MovieAudience {

   public static void main(String[] args) {

       // input (hard-coded) Do not change.
       short[] agesOfAudience = { 39, 17, 67, 15, 56, 15, 92, 25, 62, 61, 79, 42, 85, 76, 58, 41, 22, 59, 83, 84, 72,
               77, 31, 48, 44, 19, 43, 98, 96, 41, 64, 27, 60, 22, 6, 99, 67, 14, 31, 15, 97, 42, 87, 62, 79, 37, 46,
               30, 97, 51, 98, 43, 40, 98, 55, 70, 22, 80, 62 };

       // processing
       // According to Wikipedia, the "key demographic" used for television
       // is 18 to 54.
       // TODO: Implement a method that will return the number of people
       // between 18 and 54 inclusive, found in any array passed in as an
       // argument. Do not change the method invocation.
       int numKeyDemo = countKeyDemographic(agesOfAudience);

       // TODO: Implement a method that will return the average of any
       // array passed in as an argument. Do not change the method invocation.
       float avg = average(agesOfAudience);

       // output
       // TODO: replace the two lines of code below with a method named
       // "displayOutput" that produces the same result
       System.out.println("The number in the key demo is: " + numKeyDemo);
       System.out.println("The average age is: " + avg);
   }
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

public class MovieAudience {

   public static void main(String[] args) {

       // input (hard-coded) Do not change.
       short[] agesOfAudience = { 39, 17, 67, 15, 56, 15, 92, 25, 62, 61, 79, 42, 85, 76, 58, 41, 22, 59, 83, 84, 72,
               77, 31, 48, 44, 19, 43, 98, 96, 41, 64, 27, 60, 22, 6, 99, 67, 14, 31, 15, 97, 42, 87, 62, 79, 37, 46,
               30, 97, 51, 98, 43, 40, 98, 55, 70, 22, 80, 62 };

       // processing
       // According to Wikipedia, the "key demographic" used for television
       // is 18 to 54.
       // TODO: Implement a method that will return the number of people
       // between 18 and 54 inclusive, found in any array passed in as an
       // argument. Do not change the method invocation.
       int numKeyDemo = countKeyDemographic(agesOfAudience);

       // TODO: Implement a method that will return the average of any
       // array passed in as an argument. Do not change the method invocation.
       float avg = average(agesOfAudience);

       // output
       // TODO: replace the two lines of code below with a method named
       // "displayOutput" that produces the same result
       System.out.println("The number in the key demo is: " + numKeyDemo);
       System.out.println("The average age is: " + avg);
   }

   private static float average(short[] arr) {
       float sum = 0;
       //iterating through the elementsand adding to sum
       for (short s : arr)
           sum += s;
       //finding the average
       return sum / arr.length;
   }

   private static int countKeyDemographic(short[] arr) {
       int count = 0;
       //iterating through the elements and adding to counting if it is between 18-54
       for (short s : arr)
           if (s >= 18 && s <= 54)
               count++;
       return count;
   }

}

Note : Please comment below if you have concerns. I am here to help you

If you like my answer please rate and help me it is very Imp for me

Add a comment
Know the answer?
Add Answer to:
public class MovieAudience {    public static void main(String[] args) {        // input (hard-coded)...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • import java.util.Random; import java.util.ArrayList; /** * */ public class hw5_task8 { public static void main(String[] args)...

    import java.util.Random; import java.util.ArrayList; /** * */ public class hw5_task8 { public static void main(String[] args) { int[] grades = randomIntArr(10); printIntArray("grades", grades); ArrayList<Integer> indexesF_AL = selectIndexes_1(grades); System.out.println(" indexesF_AL: " + indexesF_AL); int[] indexesF_Arr = selectIndexes_2(grades); printIntArray("indexesF_Arr",indexesF_Arr); } public static int[] randomIntArr(int N){ int[] res = new int[N]; Random r = new Random(0); for(int i = 0; i < res.length; i++){ res[i] = r.nextInt(101); // r.nextInt(101) returns an in in range [0, 100] } return res; } public static void...

  • import java.util.Scanner; public class TriangleMaker {    public static void main(String[] args) {        //...

    import java.util.Scanner; public class TriangleMaker {    public static void main(String[] args) {        // TODO Auto-generated method stub        System.out.println("Welcome to the Triangle Maker! Enter the size of the triangle.");        Scanner keyboard = new Scanner(System.in);    int size = keyboard.nextInt();    for (int i = 1; i <= size; i++)    {    for (int j = 0; j < i; j++)    {    System.out.print("*");    }    System.out.println();    }    for (int...

  • import java.util.Scanner; public class Lab6d { public static void main(String[] args) {    Scanner scnr =...

    import java.util.Scanner; public class Lab6d { public static void main(String[] args) {    Scanner scnr = new Scanner(System.in); // TODO: get user choice    // TODO: call printTable method passing choice as the parameter    } public static void printTable(int stop) { // TODO: print header    // TODO: loop to print table rows up to stop value    } Write a Java program where the main () method prompts the user to select an integer value between 1 and...

  • Priority Queue Demo import java.util.*; public class PriorityQueueDemo {    public static void main(String[] args) {...

    Priority Queue Demo import java.util.*; public class PriorityQueueDemo {    public static void main(String[] args) {        //TODO 1: Create a priority queue of Strings and assign it to variable queue1               //TODO 2: Add Oklahoma, Indiana, Georgia, Texas to queue1                      System.out.println("Priority queue using Comparable:");        //TODO 3: remove from queue1 all the strings one by one        // with the "smaller" strings (higher priority) ahead of "bigger"...

  • Java Here is the template public class ShiftNumbers { public static void main(String[] args) { // TODO:...

    Java Here is the template public class ShiftNumbers { public static void main(String[] args) { // TODO: Declare matrix shell size // TODO: Create first row // TODO: Generate remaining rows // TODO: Display matrix } /** * firstRow * * This will generate the first row of the matrix, given the size n. The * elements of this row will be the values from 1 to n * * @param size int Desired size of the array * @return...

  • [JAVA] help —————— ListArrayMain.java ——————- public class ListArrayMain { public static void main (String[] args) {...

    [JAVA] help —————— ListArrayMain.java ——————- public class ListArrayMain { public static void main (String[] args) { ListArray L1 = new ListArray(); // constructs the list L1 L1.InsertBegin(2); L1.InsertBegin(3); L1.InsertBegin(7); L1.InsertBegin(15); L1.InsertBegin(5); L1.InsertEnd(666); L1.InsertAfter(1000,7); // Now, let's print out the array to verify the insertions worked. System.out.println("The items in the list are:"); for (int i = 0; i<= L1.lastCell; i++) { System.out.println(L1.a[i]); } System.out.println("The last cell number is: " + L1.lastCell); }// end main } ———————————- ListArray.java ———————————— public class ListArray...

  • public class SquareTest {    public static void main(String[] args) {               System.out.println("Number...

    public class SquareTest {    public static void main(String[] args) {               System.out.println("Number of sides is " + Square.NUM_OF_SIDES);                      Square s1 = new Square(-5.7f);               System.out.println(s1);               s1.setLength(0.001f);        System.out.println(s1.getLength());               s1.setLength(-9999);        System.out.println(s1.getLength());               System.out.println("Number of sides is " + s1.NUM_OF_SIDES);               s1.calculateArea();                            } }...

  • For Java please.Artwork. javaimport java.util.Scanner;public class ArtworkLabel {public static void main(String[] args)...

     Given main(). define the Artist class (in file Artist java) with constructors to initialize an artist's information, get methods, and a printlnfo() method. The default constructor should initialize the artist's name to "None' and the years of birth and death to 0. printinfo() should display Artist Name, born XXXX if the year of death is -1 or Artist Name (XXXX-YYYY) otherwise. Define the Artwork class (in file Artwork.java) with constructors to initialize an artwork's information, get methods, and a printinfo() method. The constructor should...

  • Code in java Using the template below: public class Lab03 { public static void main(String[] args)...

    Code in java Using the template below: public class Lab03 { public static void main(String[] args) { ArrayList<Integer> list1 = new ArrayList<Integer>(); Collections.addAll(list1, 1, 3, 5, 5 ); ArrayList<Integer> list2 = new ArrayList<Integer>(); Collections.addAll(list2, 3, 7, 3, 2, 4 ); ArrayList<Integer> result1= uniqueUnion(list1,list2); System.out.println(result1); Integer[] array = new Integer[]{ 29, 28, 27, 16, 15, -14, 3, -2, 2}; ArrayList<Integer> arrayList = new ArrayList<Integer>(Arrays.asList(array)); System.out.printf("The average is: %.2f%n", averagePositive(arrayList)); } // end main public static ArrayList<Integer> uniqueUnion(ArrayList<Integer> list1, ArrayList<Integer> list2) {...

  • import java.util.Scanner; public class StudentClient {       public static void main(String[] args)    {   ...

    import java.util.Scanner; public class StudentClient {       public static void main(String[] args)    {        Student s1 = new Student();         Student s2 = new Student("Smith", "123-45-6789", 3.2);         Student s3 = new Student("Jones", "987-65-4321", 3.7);         System.out.println("The name of student #1 is ");         System.out.println("The social security number of student #1 is " + s1.toString());         System.out.println("Student #2 is " + s2);         System.out.println("the name of student #3 is " + s3.getName());         System.out.println("The social security number...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT