Question

In: Computer Science

Create an application containing an array that stores 5 integers. The application should call five methods...

Create an application containing an array that stores 5 integers. The application should call five methods from Array2 class that in turn (1) display all the integers, (2) display all the integers in reverse order, (3) display the sum of the integers, (4) display all values less than a limiting argument, and (5) display all values that are higher than the calculated average value. Save the file as ArrayTest.java.

Solutions

Expert Solution

In the below code , two classes are declared : Array2 and ArrayTest

5 methods are defined in Array2 class:

display(): to display all array elements, For loop used for it

Reverse(): display elements in reverse order , one more array is used, reversed elements are stored in it and displaed. For loop used for it

SumOfArray(): added all the elements of array and displayed in console

lessLimitingArgument(): one limit element is passed as argument, all the elements less than that element in array are displayed in console

highAverageElement(): average of elements of array is found and elements greater than average are displayed in console

In ArrayTest class:

Elements of array are inputted from console

object of Array2 class in declared and all the function of Array2 class are called

________________________________________

Please find the code in Java:

import java.util.*;
class Array2{
void display(int[] arr){
System.out.println("List of elements in array are: ");
for(int i=0;i<arr.length;i++){
System.out.println(arr[i]);
}
}
void reverse(int[] arr){
System.out.println("Reversed array elements are: ");
int[] reverseArr=new int[arr.length];
int j=0;
for(int i=arr.length-1;i>=0;i--){
reverseArr[i]=arr[j];
j++;
}
for(int i=0;i<reverseArr.length;i++){
System.out.println(reverseArr[i]);
}
}
void sumOfArray(int[] arr){
int sum=0;
for(int i=0;i<arr.length;i++){
sum+= arr[i];
}
System.out.println("Sum of elements of array is: "+sum);

}
void lessLimitingElement(int[] arr,int limit){
  
  
System.out.println("Elements less than limiting argument are: ");
for(int i=0;i<arr.length;i++){
if(limit>arr[i]){
System.out.println(arr[i]);
}
}
  
}
void highAverageElement(int[] arr){
int avg=0,sum=0;
for(int i=0;i<arr.length;i++){
sum+= arr[i];
}
avg=sum/arr.length;
System.out.println("Elements higher than average are: ");
for(int i=0;i<arr.length;i++){
if(avg<arr[i]){
System.out.println(arr[i]);
}
}
  
}
}
public class ArrayTest
{
   public static void main(String[] args) {
   Scanner scr=new Scanner(System.in);
      
       int[] arr=new int[5];
       System.out.println("Enter 5 Elements in array:");
       for(int i=0;i<arr.length;i++){
arr[i]=scr.nextInt();
}
System.out.println("Enter limiting element : ");
       int limit=scr.nextInt();
       Array2 obj=new Array2();
       obj.display(arr);
       obj.reverse(arr);
       obj.sumOfArray(arr);
       obj.lessLimitingElement(arr,limit);
       obj.highAverageElement(arr);
   }
}

Please find the OUTPUT screenshot:


Related Solutions

Create an application containing an array that stores 20 prices, such as 2.34, 7.89,1.34, and so...
Create an application containing an array that stores 20 prices, such as 2.34, 7.89,1.34, and so on. The application should (1) display the sum of all the prices, (2) display all values less than 5.00, (3) calculate the average of the prices, and (4) display all values that are higher than the calculated average value. Write a program in Java which performs the sort operation. The main method accepts ten numbers in an array and passes that to the method...
Create an application named MaxRowSum.java that instantiates a 20x20 two-dimentional array of integers, populates it with...
Create an application named MaxRowSum.java that instantiates a 20x20 two-dimentional array of integers, populates it with random integers drawn from the range 1 to 100, and then output the index of the row with the highest sum along all the rows. To support your solution, create a class named RowSumThread.java from which you can instantiate Runnable objects, each of which will sum one row of the two-dimensional array and then place the sum of that row into the appropriate slot of a one-dimensional, 20-element array. To Summarize, your application will: 1. Generate the two-dimensional array of random integers 2. Start 20 concurrent threads, each of which places the sum of one row of the two-dimensional array into the corresponding slot of a one-dimensional array. 3. Onput the index of the row with the maximum value.
Create an application named MaxRowSum.java that instantiates a 20x20 two-dimentional array of integers, populates it with...
Create an application named MaxRowSum.java that instantiates a 20x20 two-dimentional array of integers, populates it with random integers drawn from the range 1 to 100, and then output the index of the row with the highest sum along all the rows. To support your solution, create a class named RowSumThread.java from which you can instantiate Runnable objects, each of which will sum one row of the two-dimensional array and then place the sum of that row into the appropriate slot...
Instructions Create an application to accept data for an array of five CertOfDeposit objects, and then...
Instructions Create an application to accept data for an array of five CertOfDeposit objects, and then display the data. import java.time.*; public class CertOfDeposit { private String certNum; private String lastName; private double balance; private LocalDate issueDate; private LocalDate maturityDate; public CertOfDeposit(String num, String name, double bal, LocalDate issue) { } public void setCertNum(String n) { } public void setName(String name) { } public void setBalance(double bal) { } public void issueDate(LocalDate date) { } public String getCertNum() { }...
5. Suppose you are given an n-element array containing distinct integers that are listed in increasing...
5. Suppose you are given an n-element array containing distinct integers that are listed in increasing order. Given a number k, describe a recursive algorithm to find two integers in A that sum to k, if such a pair exists. What is the running time of your algorithm? Java Language....
Create a python application that inputs, processes and stores student data. Specifications: 1. Your application should...
Create a python application that inputs, processes and stores student data. Specifications: 1. Your application should be able to accept Student data from the user and add the information in a file type of your choice. 2. your application is a menu driven and allow the user to choose from the following menu Menu: 1 – Add students to file 2 – print all the student information 3 – print specific student information using studentID 4 – Exit the program...
Q.1: Use the NumPy’s random number generation to create an array of five random integers that...
Q.1: Use the NumPy’s random number generation to create an array of five random integers that represent summertime temperatures in the range 60–100, then perform the following tasks: a. Convert the array into the Series named temperatures and display it. b. Determine the lowest, highest and average temperatures. c. Produce descriptive statistics for the Series. Q.2: Given the following dictionary; temps = {'Mon': [68, 89], 'Tue': [71, 93], 'Wed': [66, 82], 'Thu': [75, 97], 'Fri': [62, 79]} perform the following...
1) Define and create an array of integers with the values 5, 7, 8, 9 10,...
1) Define and create an array of integers with the values 5, 7, 8, 9 10, 12 using an initializer list. Print the array. 5. 2) Given the Array below, replace the element at position 3 with the value, 99, using an assignment statement. int [] list = {88, 0, 11, 22, 55, 77}; What is the value of list.length?
In C create an array of 4 integers. Assign a pointer to the array. Use the...
In C create an array of 4 integers. Assign a pointer to the array. Use the pointer to find the average value of the elements in the array and display the results on the screen.
Write array methods that carry out the following tasks for an array of integers by creating...
Write array methods that carry out the following tasks for an array of integers by creating and completing the “ArrayMethods” class below. Add documentation comments for each method. Provide a test program called ‘Lab5_yourID.java” that test methods of ArrayMethods class. In your test program, use random class to generate array values. public class ArrayMethods { private int[ ] values; //declare instant variables public ArrayMethods (int[ ] initialValues) {values = initialValues;} //constructor public void shiftRight( ) { … } public Boolean...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT