Hi, I am required to: Create an array of 100 integers using a random generator. ( 1 for loop) Provide the sum and average of the array. (1 for loop) Find the smallest and largest number in the array. Determine its position in the array. (2 for loops) How many numbers are below the average, and how many numbers are above the average. (1 for loop) Print all data to the console, but do not print the array to the console. Unfortunately, the code that was sent to help me has come up with a bunch of errors. I really need help with identifiying which errors it is. Certain things look right but I'm sure where the errors are coming from.  Please include detailed descriptions and step by steps of how to correct this code for java.   //importing package for Random classimport java.util.Random; //main classpublic class Project_7 {//main method public static void main(String[] args) {//declaring an integer loop variable//declaring variable long type for storing the sum of all array elementslong sum=0;int i;//initiating random class Random randomNum = new Random();//creating an array with size of 100 elements int[] arrayNum = new int[100]; //using for loop to store the value in array created by random generatorfor(i=0;i<100; i++){//assigning random values to array arrayNum[i]=randomNum.nextInt(100);}//for loop to calculate the sum of all the array elementssum += arrayNum[i];}//printing out sum of array elements to console System.out.println("sum of array:"+sum); //calculating the average of array elements by dividing the sum of array elements by 100 i.e., total number of elements double avg = (double)sum/100;//calculating average of all array elementsSystem.out.println("average of array:" +avg);//assigning value of first index value to min int min = arrayNum[0];//initializing minindexvalue with 0int minindexvalue = 0;//using for loop to calculate the minimum array elements for(i=0;i<100;i++){//checking if the array element is smaller than min variableif(arrayNum[i]<min){//if the array element is smaller then assigning its value to the min variable min = arrayNum[i];//storing index valueminindexvalue = i;}}//displaying the minimum value and its index value to userSystem.out.println("Smallest number in the array is "+min+" and its position in the array is "+minindexvalue);//assigning value of first array element to the max int max = arr[0]; //initializing maxindexvalue with 0 int maxindexvalue = 0; //for loop for finding the maximum value of array element for(i=0;i<100;i++){ //checking if the value of array element is greater than max if(arr[i]>max) { //assigning the value of array element to max variable max = arr[i]; //storing index of max variable maxindexvalue = i; } } //dispalying the maximum value and its index value to user System.out.println("Largest number in the array is "+max+" and its position in the array is "+maxindexvalue); //varible for counting the number below the average int num_below_average =0; //varible for counting the number above the average int num_above_average =0; //for loop to find the number is below or above to the average for( i=0;i<100;i++) { //if the value is greater than average if((double)arr[i]<avg) { //incrementing the value of num_below_average num_below_average++; } //if the value is smaller than average else { //incrementing the value of num_above_average num_above_average++; } } //displayin the Numbers below the average: System.out.println("Numbers below the average: "+num_below_average); //displayin the Numbers above the average: System.out.println("Numbers above the average: "+num_above_average);   } } { } }

Question

Hi, I am required to:

  • Create an array of 100 integers using a random generator. ( 1 for loop)
  • Provide the sum and average of the array. (1 for loop)
  • Find the smallest and largest number in the array. Determine its position in the array. (2 for loops)
  • How many numbers are below the average, and how many numbers are above the average. (1 for loop)
  • Print all data to the console, but do not print the array to the console.

Unfortunately, the code that was sent to help me has come up with a bunch of errors. I really need help with identifiying which errors it is. Certain things look right but I'm sure where the errors are coming from. 

Please include detailed descriptions and step by steps of how to correct this code for java.

 

//importing package for Random class
import java.util.Random;

//main class
public class Project_7
{
//main method
public static void main(String[] args)
{
//declaring an integer loop variable


//declaring variable long type for storing the sum of all array elements
long sum=0;
int i;
//initiating random class
Random randomNum = new Random();

//creating an array with size of 100 elements
int[] arrayNum = new int[100];

//using for loop to store the value in array created by random generator

for(i=0;i<100; i++)
{
//assigning random values to array
arrayNum[i]=randomNum.nextInt(100);
}
//for loop to calculate the sum of all the array elements
sum += arrayNum[i];
}

//printing out sum of array elements to console
System.out.println("sum of array:"+sum);


//calculating the average of array elements by dividing the sum of array elements by 100 i.e., total number of elements
double avg = (double)sum/100;

//calculating average of all array elements
System.out.println("average of array:" +avg);

//assigning value of first index value to min
int min = arrayNum[0];

//initializing minindexvalue with 0
int minindexvalue = 0;

//using for loop to calculate the minimum array elements
for(i=0;i<100;i++)
{
//checking if the array element is smaller than min variable
if(arrayNum[i]<min)
{
//if the array element is smaller then assigning its value to the min variable
min = arrayNum[i];

//storing index value
minindexvalue = i;
}
}

//displaying the minimum value and its index value to user
System.out.println("Smallest number in the array is "+min+" and its position in the array is "+minindexvalue);

//assigning value of first array element to the max

int max = arr[0];

//initializing maxindexvalue with 0

int maxindexvalue = 0;

//for loop for finding the maximum value of array element

for(i=0;i<100;i++){

//checking if the value of array element is greater than max

if(arr[i]>max)

{

//assigning the value of array element to max variable

max = arr[i];

//storing index of max variable

maxindexvalue = i;

}

}

//dispalying the maximum value and its index value to user

System.out.println("Largest number in the array is "+max+" and its position in the array is "+maxindexvalue);

//varible for counting the number below the average

int num_below_average =0;

//varible for counting the number above the average

int num_above_average =0;

//for loop to find the number is below or above to the average

for( i=0;i<100;i++)

{

//if the value is greater than average

if((double)arr[i]<avg)

{

//incrementing the value of num_below_average

num_below_average++;

}

//if the value is smaller than average

else

{

//incrementing the value of num_above_average

num_above_average++;

}

}

//displayin the Numbers below the average:

System.out.println("Numbers below the average: "+num_below_average);

//displayin the Numbers above the average:

System.out.println("Numbers above the average: "+num_above_average);

 

}

}




{

}

}

Expert Answer

Want to see the step-by-step answer?

Check out a sample Q&A here.

Want to see this answer and more?

Experts are waiting 24/7 to provide step-by-step solutions in as fast as 30 minutes!*

*Response times may vary by subject and question complexity. Median response time is 34 minutes for paid subscribers and may be longer for promotional offers.
Tagged in
Engineering
Computer Science

Related Computer Science Q&A

Find answers to questions asked by students like you.

Q: NOTE: in mathematics, the square root of a negative number is not real; in C++ therefore, passing su...

A: A C++ program is to be created  that will read the value for area of square and will print the lengt...

Q: Many documents use a specific format for a person's name. Write a program whose input is: firstName ...

A: This program can be done in a very easy way. Programming instruction: First, take the input from the...

Q: This is the question: Suppose that we want to synthesize a circuit that has two switches x and y. Th...

A: Here in this synthesize circuit NOT AND and OR gate is used. So let us try to understand the figure ...

Q: Python   1. Write a for loop (using the range() function) that will print the integers 10,15,20,25,3...

A: Program:#display the statementprint("The integers are: ") #iterate "i" in the range of 10 to 51 with...

Q: Write a program that asks for the name of an input file. Then, read all the numbers in the file, and...

A: Create a PYTHON3 file in which import io module and validate file in program.Print sum, number of el...

Q: First, launch NetBeans and close any previous projects that may be open (at the top menu go to File ...

A: Create a Java class MultiTable which uses 2 for-loops to create multiplication table.Outer for-loop ...

Q: What is a nested function?  and what part in the following code is considered a nest function??     ...

A:  NOTE:Programming language is not mentioned in the question. The following explanations are given ba...

Q: Python 3.7.4 Write a statement to open the file priceList.txt for writing.

A: To open the file priceList.txt for writing, the statement is: f=open('priceList.txt','w')The followi...

Q: Using the types of entities found in the Colonial Adventure Tours database (trips, guides, clients, ...

A: The Set of entities provided for Colonial Adventure Tours Database includes Trips, Guides, Clients a...

Q: this is for python

A: Python program to display a diagonal tableThe variables and functions used to solve this problem inc...

Q: I have tried this  a few times and cannot figure it out. This is for python.

A: The sub lists can be printed by printing each row; hence the answer would be:for i in range(len(tabl...

Q: Write a program that generates a two-column table showing Fahrenheit temperatures from -40F to 120F ...

A: Java program://Create a class name "temperature"public class temperature{     //Definition for main ...

Q: I need help with this programming exercise:   Write a C++ console application that allows your user ...

A: Program code #1:

Q: Create a class of type student .Members will include: name, gpa, rank (year) Make sure all data is p...

A: The name of the class is Student.All data is a private member of the class.All function is a public ...

Q: Create a project called Mileage. In it, create a class Car with the following properties. A car has ...

A: To Create a project called Mileage. In it, create a class Car with the following properties. A car h...

Q: Vectors Write three statements to print the first three elements of vector runTimes. Follow each wit...

A: Program DescriptionThe program prompts the user to input 5 numbers to populate the vectorIt tests th...

Q: In Python Use the Design Recipe to write a function,  print_histogram  that consumes a list of numbe...

A:  Programming Instructions: Define the function print_histogram which takes the list of integers as a...

Q: Write a program Gas.java that computes and displays the price a person will pay for gas at the gas s...

A: public class Gas {      public static void main(String[] args)       {             if (args.length &...

Q: Python 3.7.4 Store four file objects corresponding to the files winter2003.txt , spring2003.txt, sum...

A: Python statements for creating file objects: winter=open("winter2003.txt", "r")spring=open("spring20...

Q: You will write 4 classes for Program 5.  Assignment:The BankAccount class models an account of a cus...

A: Java Program:Filename :- BankAccount.java// Import the required packageimport java.util.Date;// Clas...

Q: A transitive dependency is equivalent to which of the following?A) A functional dependency between t...

A: Transitive dependencyA transitive dependency in a database is an indirect relationship between value...

Q: what is mantissa and exponent values of 6.75

A: Convert decimal number (6.25)10 to binary:First, convert integer value (6)10 to binary:To obtain bin...

Q: I want to see how one can add 80 elements into an array without manually entering in each element.  ...

A: Given,The name of the first array is numberArray1 and the size of the array is 80.The name of the se...

Q: In Python Use the Design Recipe to write a function has_duplicates, which consumes a list and return...

A: This program returns true when a list has duplicate value, if the list has not any duplicate value t...

Q: In MS Access, which kind of values will be accepted by the databasethrough input mask&gt;L0L0L0;0;#A...

A: An input mask in MS-Access contain 3 fields.These fields are separated by semi-colonFirst field spec...

Q: in python Write a program that creates a list of your friends. Start with an empty list and then us...

A: List:  A list in python is a data structure which stores data or items of various data types. A list...

Q: How would you modify the dynamic programming algorithm for the coin collecting problem if some cells...

A: Coin collecting problemIn a n-m board, several coins are placed in such a way no more than one coin ...

Q: I am getting stuck on the code to see if its a factor or not. Im not sure where I went wrong.

A: The following is the source code which prints whether a number is a factor of generated random numbe...

Q: Describe the activities that occur during project development.

A: Project development is a process in which resources are planned, organized and coordinated to achiev...

Q: Design a reasonably efficient algorithm for solving each of the following problems and determine its...

A: AlgorithmLet x be one of the numbers and the other number is n-x. The first step is to maximize f(x)...

Q: An administrator has received a call indicating that some users are having difficulty logging on aft...

A: Domain Controller:Domain controller is a server computer on Microsoft servers.The purpose of domain ...

Q: Siobhan’s laptop has 8GB of RAM. Her operating system takes up 2GB, and her application programs use...

A: Random Access Memory (RAM):RAM is a memory device used for storage purposes.The data stored in the m...

Q: Write a C++ program: A palindrome is a word that reads the same forwards and backwards for example "...

A: Program:#include&lt;iostream&gt;#include&lt;bits/stdc++.h&gt;using namespace std;void Palindrome_Che...

Q: Python 3.7.4 Write a statement that associates d with an empty dictionary.

A: Following is the code statement to associate d with empty dictionary:A dictionary is an unordered, v...

Q: Active Directory metadata describes the actual Active Directory data, not the Active Directory datab...

A: Active Directory:The Microsoft Technology used to manage computers and the other devices in a networ...

Q: Brief paragraph needed: We know that the Pep/9 simulated hardware has 64K of memory. But, how is tha...

A: Pep/9 hardwareThe pep/9 hardware consists of three components that is disk, central processing unit ...

Q: Given a nested list named table, use a loop to print each sub list of the nested list. The sub lists...

A: Program descriptionOne 3 x3 list is created to demonstrate the conceptdisplay the elements of the su...

Q: In MS Access, to ensure that a grade must be either A, B, C, D or F, whichvalidation rule should be ...

A: Microsoft (MS) AccessMicrosoft access is a database management system from Microsoft that combines r...

Q: Question 4

A: In C, strings are ended with a special null character to mark its end. Hence, when a string is store...

Q: CAREER B VENT LYY a sqeo1 NON 0LO no o N aND Welcome | MYSAIL Oakland Un X Th Course: CSI-1420-43702...

A: This program is written in C language. Year is given as input and Easter Sunday's Month and day is c...

Q: Translate the following pseudocode for finding the minimum value from a set of inputs into a Java pr...

A: Java program to find the minimum valueimport java.util.Scanner; public class Program{     Public sta...

Q: Using C++ 11 Write a program which overloads fractions arithmetic operations for division. And inclu...

A: To write a program which overloads fractions arithmetic operation for division add the following mai...

Q: WHAT IS A DOUBLE SPEND PROBLEM OF DITIAL CASH TRANSACTION? HOW THE DOUBLE SPEND PROBLEM OF DIGITAL C...

A: Double spending: It means spending the same amount of money twice. Here's a good example to explain ...

Q: Preffered language is java. Will be compiled with intellij Problem 1 consists of multiple parts. You...

A: Since there are multiple questions and you have not specified which part needs to be answered, we ha...

Q: I have written a code following the instructions below, but the choice 2, convert Fahrenheit to Cels...

A: Reason for not asking the user to enter another value:In the code given in the question, if the choi...

Q: Hi, I have to display the first 20 Fibonacci numbers to the console. The first two numbers are given...

A: Program: class PrSpecial { public static final int N = 20; public static void main(String[] args){ i...

Q: Using the data file capabilities of C++, create a Personnel file, personnel.dat on your drive and th...

A: Program Instructions:Use do-while loop to repeatedly present the menu.Use switch statement to opt di...

Q: Which of the following diagrams do not contradict the current state of our knowledge about the compl...

A: P class problems can be solved in deterministic polynomial time. NP class can be verified in the pol...

Q: Required program is java   Create a class called DuplicateRemover. Create an instance method called ...

A: Program Instructions:In class DuplicateRemover, declare a set of Strings and create methods remove()...

Q: What 1s the output of the following code! { String myStr = new String("Cheggers2019") ; System.out.p...

A: There seems to be some error in the question, hence we are proceeding with a small assumption on our...