Question

Develop a set of static methods in a class called Array Tools that perform the functions below, and overload the methods for

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code Screenshot:

Main.java 1 import java.util.*; 2 public class Main 3 - { 4 static char minimum(char array[]) int n=array.length; char min=ar

static double maximum( double array[]), int n=array.length; double max=array[0]; for(int i=1;i<n;i++) if(array[i]>max) max=ar
static int maximumAt(char array[]) int n=array.length; char max=array[0]; int maxat=0; for(int i=1;i<n;i++) if(array[i]>max)
static double average (double array[]), 172 173 - 174 175 176 int n=array.length; double sum=0.0, avg; 177 for(int i=0;i<n;i+

Output:

Enter no of element in array Enter Char array: bd a hec Enter Integer array: 7 3 5 2 8 4 Enter Double array: 3.5 6.7 8.4 9.4

Code:

import java.util.*;
public class Main
{
static char minimum(char array[])
{
int n=array.length;
char min=array[0];
for(int i=1;i<n;i++)
{
if(array[i]<min)
min=array[i];
}
return min;
}
static int minimum(int array[])
{
int n=array.length;
int min=array[0];
for(int i=1;i<n;i++)
{
if(array[i]<min)
min=array[i];
}
return min;
}
static double minimum(double array[])
{
int n=array.length;
double min=array[0];
for(int i=1;i<n;i++)
{
if(array[i]<min)
min=array[i];
}
return min;
}
static char maximum(char array[])
{
int n=array.length;
char max=array[0];
for(int i=1;i<n;i++)
{
if(array[i]>max)
max=array[i];
}
return max;
}
static int maximum(int array[])
{
int n=array.length;
int max=array[0];
for(int i=1;i<n;i++)
{
if(array[i]>max)
max=array[i];
}
return max;
}
static double maximum(double array[])
{
int n=array.length;
double max=array[0];
for(int i=1;i<n;i++)
{
if(array[i]>max)
max=array[i];
}
return max;
}
static int minimumAt(char array[])
{
int n=array.length;
char min=array[0];
int minat=0;
for(int i=1;i<n;i++)
{
if(array[i]<min)
{
min=array[i];
minat=i;
}
}
return minat;
}
static int minimumAt(int array[])
{
int n=array.length;
int min=array[0];
int minat=0;
for(int i=1;i<n;i++)
{
if(array[i]<min)
{
min=array[i];
minat=i;
}
}
return minat;
}
static int minimumAt(double array[])
{
int n=array.length;
double min=array[0];
int minat=0;
for(int i=1;i<n;i++)
{
if(array[i]<min)
{
min=array[i];
minat=i;
}
}
return minat;
}
static int maximumAt(char array[])
{
int n=array.length;
char max=array[0];
int maxat=0;
for(int i=1;i<n;i++)
{
if(array[i]>max)
{
max=array[i];
maxat=i;
}
}
return maxat;
}
static int maximumAt(int array[])
{
int n=array.length;
int max=array[0];
int maxat=0;
for(int i=1;i<n;i++)
{
if(array[i]>max)
{
max=array[i];
maxat=i;
}
}
return maxat;
}
static int maximumAt(double array[])
{
int n=array.length;
double max=array[0];
int maxat=0;
for(int i=1;i<n;i++)
{
if(array[i]>max)
{
max=array[i];
maxat=i;
}
}
return maxat;
}
static double average(int array[])
{
int n=array.length;
double sum=0.0,avg;

for(int i=0;i<n;i++)
{
sum+=array[i];
}
avg=sum/n;
return avg;
}
static double average(double array[])
{
int n=array.length;
double sum=0.0,avg;

for(int i=0;i<n;i++)
{
sum+=array[i];
}
avg=sum/n;
return avg;
}
  
   public static void main(String[] args) {
   Scanner scnr=new Scanner(System.in);
   System.out.println("Enter no of element in array");
   int n=scnr.nextInt();
   char []chararr=new char[n];
   System.out.println("Enter Char array: ");
   for(int i=0;i<n;i++)
   {
   chararr[i]=scnr.next().charAt(0);
   }
   int []intarr=new int[n];
   System.out.println("Enter Integer array: ");
   for(int i=0;i<n;i++)
   {
   intarr[i]=scnr.nextInt();
   }
   double []doublearr=new double[n];
   System.out.println("Enter Double array: ");
   for(int i=0;i<n;i++)
   {
   doublearr[i]=scnr.nextDouble();
   }
   System.out.println("Minimum Element of Char Array: "+minimum(chararr));
   System.out.println("Minimum Element of Int Array: "+minimum(intarr));
   System.out.println("Minimum Element of Double Array: "+minimum(doublearr));
   System.out.println("Maximum Element of Char Array: "+maximum(chararr));
   System.out.println("Maximum Element of Int Array: "+maximum(intarr));
   System.out.println("Maximum Element of Double Array: "+maximum(doublearr));
  
   System.out.println("Minimum Element of Char Array at index: "+minimumAt(chararr));
   System.out.println("Minimum Element of Int Array at index: "+minimumAt(intarr));
   System.out.println("Minimum Element of Double Array at index: "+minimumAt(doublearr));
   System.out.println("Maximum Element of Char Array at index: "+maximumAt(chararr));
   System.out.println("Maximum Element of Int Array at index: "+maximumAt(intarr));
   System.out.println("Maximum Element of Double Array at index: "+maximumAt(doublearr));
  
   System.out.println("Average of Int Array: "+average(intarr));
   System.out.println("Average of Double Array: "+average(doublearr));
   }
}
//Please Thumbs Up if it helps you:)

Add a comment
Know the answer?
Add Answer to:
Develop a set of static methods in a class called Array Tools that perform the functions...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • . Design a class named MyInteger. The class contains: An int data field named value that...

    . Design a class named MyInteger. The class contains: An int data field named value that stores the int value represented by this object. A constructor that creates a MyInteger object for the specified int value. A getter method that returns the int value. The methods isEven(), is Odd(), and isPrime() that return true if the value in this object is even, odd, or prime, respectively. The static methods isEven(int), isOdd(int), and isPrime(int) that return true if the specified value...

  • Do the following: - Write and test a function that takes an array of doubles and...

    Do the following: - Write and test a function that takes an array of doubles and returns the average of the values in the array - Write and test a function that takes an array of doubles and returns number of values in the array that are above the average of the values in the array - Write and test a function that takes an array of Strings and returns number of values in the array that start with an...

  • 5. (40 Points) Write a complete Java class named ArrayMethods that implements the methods listed below....

    5. (40 Points) Write a complete Java class named ArrayMethods that implements the methods listed below. All the methods accept the following parameters: Parameters: intar An array of int values. int firstIndex The index of the first element to include in the sum. int lastIndex The index of the last element to include in the sum. Please note that all methods must verify the validity of first Index and lastIndex. public static int sum(int[] arr, int first Index, int lastIndex)...

  • Java Programming Assignment Write a class named 2DArrayOperations with the following static methods: getTotal . This...

    Java Programming Assignment Write a class named 2DArrayOperations with the following static methods: getTotal . This method should accept a two-dimensional array as its argument and return the total of all the values in the array. Write overloaded versions of this method that work with int , double , and long arrays. (A) getAverage . This method should accept a two-dimensional array as its argument and return the average of all the values in the array. Write overloaded versions of...

  • Write a program that instantiates an array of integers named scores. Let the size of the...

    Write a program that instantiates an array of integers named scores. Let the size of the array be 10. The program then first invokes randomFill to fill the scores array with random numbers in the range of 0 -100. Once the array is filled with data, methods below are called such that the output resembles the expected output given. The program keeps prompting the user to see if they want to evaluate a new set of random data. Find below...

  • Static methods can be called directly from the name of the class that contains the method. Static methods are usually created to do utility operations. For example: public class Test{ public static i...

    Static methods can be called directly from the name of the class that contains the method. Static methods are usually created to do utility operations. For example: public class Test{ public static int timesTwo(int value){ return value * value; } } public class TestDriver{ public static void main(String[] args){ int var = Test.timesTwo(5);   System.out.println(var); } } For your final exercise, create a class called ManyLinkedLists. It will contain a static method called createLinkedList(). That method takes an argument that is...

  • Implement a Java class that is called RainFall that uses a double array to store the...

    Implement a Java class that is called RainFall that uses a double array to store the amount of rainfall for each month of the year. The class should have only one instance variable of type double[]. Implement the following methods in the RainFall class: 1. A constructor that creates and initializes all entries in the array to be -1. 2. toString: a method that returns a one-line String representation of the object that includes 12 double numbers that represent the...

  • Programming Assignment #7 (Recursion) This assignment is to write some methods that perform simple array operations...

    Programming Assignment #7 (Recursion) This assignment is to write some methods that perform simple array operations recursively. Specifically, you will write the bodies for the recursive methods of the ArrayRecursion class, available on the class web page. No credit will be given if any changes are made to ArrayRecursion.java, other than completing the method bodies Note that the public methods of ArrayRecursion – contains(), getIndexOfSmallest(), and sort() – cannot be recursive because they have no parameters. Each of these methods...

  • 1. Write a complete program based on public static int lastIndexOf (int[] array, int value) {...

    1. Write a complete program based on public static int lastIndexOf (int[] array, int value) { for (int i = array.length - 1; i >= 0; i--) { if (array [i] == value) { return i; } } return -1; write a method called lastindexof that accepts an array of integers and an integer value as its parameters and returns the last index at which the value occurs in the array. the method should return -1 if the value is...

  • Complete these 2 Java functions (the instructions are attached below): private static int minIndexBinarySearch(int array[], int...

    Complete these 2 Java functions (the instructions are attached below): private static int minIndexBinarySearch(int array[], int arrayLength, int key) { // Complete this function. } private static int maxIndexBinarySearch(int array[], int arrayLength, int key) { // Complete this function. } In certain applications, we are interested in counting the number of times key appears in a sorted array. The technique to solve such problems is to determine: - minIndex: the minimum index where key appears - maxIndex: the maximum index...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT