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

Arrayoperations Class Write a class name Arrayoperations with the following stat

ID: 3720070 • Letter: A

Question

Arrayoperations Class Write a class name Arrayoperations with the following static methods getrotal. This method s return the total of the valucs in the array. Write overloaded versions of this method that work with int, float, doublo, and long arrays. getaverage. This method should accept a one-dimensional array as its argument and return the average of the values in the array. Write overloaded versions of this method that work with int, float, double, and long arrays getHighest. This method should accept a one-dimensional array as its argument and return the highest value in the array. Write overloaded versions of this method that work with int, float, double, and long arrays. getLowest. This method should accept a one-dimensional array as its argument and return the lowest value in the array. Write overloaded versions of this method that work with int, float, double, and long arrays. should accept a one-dimensional array as its argument and . Demonstrate the class in a complete program with test data stored in arrays of various data

Explanation / Answer

import java.util.*;


class ArrayOperations
{
public static void main (String[] args)
{
  int[] intArray = {56,78,12,45,10};
  
  System.out.println("Int Total : "+getTotal(intArray));
  System.out.println("Int Average : "+getAverage(intArray));
  System.out.println("Int Highest : "+getHighest(intArray));
  System.out.println("Int Lowest : "+getLowest(intArray));
  
  System.out.println();
  
  float[] floatArray = {56.7f,78.4f,12.5f,45.1f,10.7f};
  
  System.out.println("float Total : "+getTotal(floatArray));
  System.out.println("float Average : "+getAverage(floatArray));
  System.out.println("float Highest : "+getHighest(floatArray));
  System.out.println("float Lowest : "+getLowest(floatArray));
  
  System.out.println();
  
  double[] doubleArray = {56.7,78.4,12.5,45.1,10.7};
  
  System.out.println("double Total : "+getTotal(doubleArray));
  System.out.println("double Average : "+getAverage(doubleArray));
  System.out.println("double Highest : "+getHighest(doubleArray));
  System.out.println("double Lowest : "+getLowest(doubleArray));
  
  System.out.println();
  
  long[] longArray = {76787,8879,588778,5778};
  
  System.out.println("long Total : "+getTotal(longArray));
  System.out.println("long Average : "+getAverage(longArray));
  System.out.println("long Highest : "+getHighest(longArray));
  System.out.println("long Lowest : "+getLowest(longArray));
  
}
public static int getTotal(int[] array)
{
  int total = 0;
  for(int i=0;i<array.length;i++)
  total = total +array[i];
  
  return total;
}
public static int getAverage(int[] array)
{
  int average = 0;
  for(int i=0;i<array.length;i++)
  average = average +array[i];
  
  return average/array.length;
}
public static int getHighest(int[] array)
{
  int highest = 0;
  for(int i=0;i<array.length;i++)
  if(highest < array[i])
  highest = array[i];
  
  return highest;
}
public static int getLowest(int[] array)
{
  int lowest = 9999;
  for(int i=0;i<array.length;i++)
  if(lowest > array[i])
  lowest = array[i];
  
  return lowest;
}

public static float getTotal(float[] array)
{
  float total = 0;
  for(int i=0;i<array.length;i++)
  total = total +array[i];
  
  return total;
}
public static float getAverage(float[] array)
{
  float average = 0;
  for(int i=0;i<array.length;i++)
  average = average +array[i];
  
  return average/array.length;
}
public static float getHighest(float[] array)
{
  float highest = 0;
  for(int i=0;i<array.length;i++)
  if(highest < array[i])
  highest = array[i];
  
  return highest;
}
public static float getLowest(float[] array)
{
  float lowest = 9999;
  for(int i=0;i<array.length;i++)
  if(lowest > array[i])
  lowest = array[i];
  
  return lowest;
}

public static double getTotal(double[] array)
{
  double total = 0;
  for(int i=0;i<array.length;i++)
  total = total +array[i];
  
  return total;
}
public static double getAverage(double[] array)
{
  double average = 0;
  for(int i=0;i<array.length;i++)
  average = average +array[i];
  
  return average/array.length;
}
public static double getHighest(double[] array)
{
  double highest = 0;
  for(int i=0;i<array.length;i++)
  if(highest < array[i])
  highest = array[i];
  
  return highest;
}
public static double getLowest(double[] array)
{
  double lowest = 9999;
  for(int i=0;i<array.length;i++)
  if(lowest > array[i])
  lowest = array[i];
  
  return lowest;
}

public static long getTotal(long[] array)
{
  long total = 0;
  for(int i=0;i<array.length;i++)
  total = total +array[i];
  
  return total;
}
public static long getAverage(long[] array)
{
  long average = 0;
  for(int i=0;i<array.length;i++)
  average = average +array[i];
  
  return average/array.length;
}
public static long getHighest(long[] array)
{
  long highest = 0;
  for(int i=0;i<array.length;i++)
  if(highest < array[i])
  highest = array[i];
  
  return highest;
}
public static long getLowest(long[] array)
{
  long lowest = 9999;
  for(int i=0;i<array.length;i++)
  if(lowest > array[i])
  lowest = array[i];
  
  return lowest;
}


}

Output:

Int Total : 201
Int Average : 40
Int Highest : 78
Int Lowest : 10

float Total : 203.40001
float Average : 40.68
float Highest : 78.4
float Lowest : 10.7

double Total : 203.4
double Average : 40.68
double Highest : 78.4
double Lowest : 10.7

long Total : 680222
long Average : 170055
long Highest : 588778
long Lowest : 5778

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