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);
}
}
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
public class MovieAudience { public static void main(String[] args) { // input (hard-coded)...
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) { // 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 = 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) { //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"...
Correct the mistakes public class customer { public static void main(String[] args) { D customer=new d(); d.employee(56,”ali”); d.department(7,8.6,9); } public void employee(String name, int age) { System.out.println("Your name is"+name); System.out.println(“Age is”+age); } public int department(double d, double t, int a) { System.out.println("I have java exam at 3:00"); Return(1.1); } } V. PROGRAMMING. Write a complete JAVA program to implement the following. 1. Create a class named Exponent. Its main() method accepts an integer value from a user at the keyboard,...
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) {
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 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(); } }...
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) {
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) {...