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

Program A. Develop a program containing 4 separate Java methods to perform the f

ID: 3698278 • Letter: P

Question

Program A.   Develop a program containing 4 separate Java methods to perform the following on a one-dimensional integer array LIST of dimension N:

Determine (i.e. “return”) the highest value in LIST.

Determine (i.e. “return”) the lowest value in LIST.

Determine (i.e. “return”) the sum of all the items in LIST.

Determine (i.e. “return”) the average of the values in LIST after eliminating the lowest and the highest values. This method should invoke some or all of the other 3 methods.

Program B.  Develop a Java program that will add the corresponding elements of two 1-dimensional arrays X and Y to produce the 1-dimensional array Z. Arrays X, Y, Z have the same dimension [M].

NOTE: In the above programs, you will need to have the user input the dimensions of the respective arrays before execution of the methods. Also, output the results of all computations.

Explanation / Answer

A.

import java .util.*;

import org.apache.commons.lang.ArrayUtils;

public class LargeSmall

{

public static void main(String[] args)

{

int [] list;

int smallest,largest,sum=0,sum1=0;

float avg;

Scanner input=new Scanner(System.in);

System.out.println("Enter Dimension: ");

int n=input.nextInt();

int list[]=new int[n];

smallest=list[0];largest=list[0];

System.out.println("Enter"+n+"element");

for(int c=0;c<list.length;c++)

{

list[c]=input.nextInt();

}

for(int i=0;i<list.length;i++)

{

if(list[i]<smallest)

smallest=list[i];

else if(list[i]>largest)

largest=list[i];

}

//printing input

System.out.println("%s%8s ""Index","Input");

for(int c=0;c<list<length;c++)

{System.out.println("%5d%8d ",list[c]);

}

System.out.println("Smalle"+smallest+"Largest="+largest);

for(intj=0;j<list.length;j++)

{

sum=sum+list[j];

}System.out.println("sum="+sum);

list=ArrayUtils.remove(list,smallest);

list=ArrayUtils.remove(list,largest);

for(int k=0;k<list.length;k++)

{

sum1=sum1+list[k];

}

avg=sum1/list.length;

System.out.println("average="+avg);

}

}

B.

import java.util.Scanner;

public class Add

{

public static void main(String args[])

{

int[]x;

int[]y;

int m;

Scanner input=new Scanner(System.in);

System.out.println("enter dimension of arrays:",);

int m=input.nextInt[m];

System.out.println("Enter"+m+"elements");

for(int i=0;i<x.length;i++)

{

x[i]=input.nextInt();

}

for(int j=0;j<y.length;j++)

{

y[j]=input.nextInt();

}

int z[]=new int[x.length];

for(int k=0;k<x.length;k++)

{

z[k]=x[k]+y[k];

}

System.out.println("sum is",+z);

}}

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