Question

In: Computer Science

Please name your driver program XXX_P03 where XXX are your initials. Please name your array utilities...

  1. Please name your driver program XXX_P03 where XXX are your initials. Please name your array utilities class ArrayUtilities. Have only static methods in your ArrayUtilities class. Make sure your program will work for any array size.

Write a driver program with a double array that is initialized with the following test data. You may hard code this data into your array.

Echo the input in a neat table formatted exactly as below (5 elements to a line and aligned). Then output the number of elements in the array, smallest, largest, range, array total and average, using the methods of the array utilities class defined below.

Java Eclipse

Solutions

Expert Solution

ArrayUtilities.java


class ArrayUtilities {
        
        // calculating the smallest value
        public static double smallest( double[] a ) {
                
                // initializing first element
                double smallest = a[0];
                
                // finding the smallest element
                for(int i=0; i<a.length ;i++) {
                        if(smallest > a[i]) {
                                smallest = a[i];
                        }
                }
                
                // returning smallest element
                return smallest;
        }
        
        // calculating the largest value 
        public static double largest( double[] a ) {
                
                // initializing largest element
                double largest = a[0];
                
                // finding largest element
                for(int i=0; i<a.length ;i++) {
                        if(largest < a[i]) {
                                largest = a[i];
                        }
                }
                
                // returning largest element
                return largest;
        }
        
        // calculating range of array
        public static String range( double[] a ) {
                double smallest = smallest(a);
                double largest = largest(a);
                // returning the range
                return String.format("[%f %f]", smallest, largest);
        }
        
        // calculating total sum of array
        public static double arrayTotal( double[] a ) {
                double total = 0;
                for(int i=0; i<a.length ;i++) {
                        total += a[i];
                }
                return total;
        }
        
        // calculating average
        public static double average( double[] a ) {
                return arrayTotal(a)/a.length;
        }
        
}

Driver.java

public class Driver {

        public static void main(String[] args) {
                
                double[] a = new double[] {3, 5, 1, 56, 9, 10};
                
                // printing all properties of array utilities
                System.out.println("Number of Elements : "+a.length);
                System.out.println("Smallest Element   : "+ArrayUtilities.smallest(a));
                System.out.println("Largest Element    : "+ArrayUtilities.largest(a));
                System.out.println("Range of Elements  : "+ArrayUtilities.range(a));
                System.out.println("Array Total        : "+ArrayUtilities.arrayTotal(a));
                System.out.println("Array Average      : "+ArrayUtilities.average(a));
                
                

        }

}

Code

ArrayUtilities.java

Driver.java

Output


Related Solutions

// This program performs a linear search on a character array // Place Your Name Here...
// This program performs a linear search on a character array // Place Your Name Here #include<iostream> using namespace std; int searchList( char[], int, char); // function prototype const int SIZE = 8; int main() { char word[SIZE] = "Harpoon"; int found; char ch; cout << "Enter a letter to search for:" << endl; cin >> ch; found = searchList(word, SIZE, ch); if (found == -1) cout << "The letter " << ch      << " was not found in...
Please write a C++ program. Please rewrite your Array (including the operator overloading) into a template....
Please write a C++ program. Please rewrite your Array (including the operator overloading) into a template. And rewrite your main function to test your template for integer array and double array. Following is my complete code: #include <iostream> using namespace std; class Array { private: // Pointer to memory block to store integers int* data; // Maximum size of memory block int cap; // Stores number of integers in an array int num; public: // Constructor Array(int size); // Default...
You will write a single class named WordsXX- replace the XX's with your initials. The program...
You will write a single class named WordsXX- replace the XX's with your initials. The program will have 2 overloaded methods named wordMaker. They will have to be declared as static. Both methods will not have a return type but they will print some text. The first method wordMaker signature will not accept any parameters and when invoked will simply print out the line "lower case words". The second overloaded wordMaker method will accept an integer and print "Words in...
You will write a single class named WordsXX- replace the XX's with your initials. The program...
You will write a single class named WordsXX- replace the XX's with your initials. The program will have 2 overloaded methods named wordMaker. They will have to be declared as static. Both methods will not have a return type but they will print some text. The first method wordMaker signature will not accept any parameters and when invoked will simply print out the line "lower case words". The second overloaded wordMaker method will accept an integer and print "Words in...
C++ PLEASE---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- In this program, you will analyze an array
C++ PLEASE---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- In this program, you will analyze an array of 10 characters storing a gene sequence. You will be given a subsequence of 3 characters to look for within this array. If the subsequence is found, print the message: Subsequence <XXX> found at index <i>. Where i is the starting index of the subsequence in the array. Otherwise, print Subsequence <XXX> not found. The array of characters and the subsequence will be given through standard input. Read them and...
In Java please Your program will sort a two dimensional array (5 * 4) based on...
In Java please Your program will sort a two dimensional array (5 * 4) based on the following: The entire array should be sorted using bubble sort based on the 1st column in ascending order and display the entire array. Reset the array to its original contents. The entire array should again be sorted using selection sort based on the 2nd column in descending order and display the entire array. Reset the array to its original contents. The entire array...
Write a program in Java with a Scanner. Given an array and a number k where...
Write a program in Java with a Scanner. Given an array and a number k where k is smaller than the size of the array, write a program to find the k'th smallest element in the given array. It is given that all array elements are distinct. Example: Input: arr[] = {7,10,4,3,20,15} k = 3 Output: 7
Seasons Re-Visited Write a program that contains an array of strings in main(). Your array of...
Seasons Re-Visited Write a program that contains an array of strings in main(). Your array of strings will contain the seasons, “Winter”, “Spring”, “Summer”, and “Fall”. Your program will then contain a function that will use your seasons array to display a menu and ask the user to choose their favorite season and return that value to the main() function. Your function must include a data validation loop. The user must enter in a 1 for winter, a 2 for...
Assignment Write a program using turtle graphics which writes your initials, or any other three unique...
Assignment Write a program using turtle graphics which writes your initials, or any other three unique letters, to the display. Look to your program for lab 1 for reminders of how to use turtle graphics. Functions that must be written: def drawLetter (x, y, letterColor): Write three functions, one for three unique letters. Personally, I would write drawA, drawR, and drawS. Each function must draw that letter to the screen. The x and y values determine the upper left-hand location...
Input: An array of non-negative integers, where each element in the array represents your maximum jump...
Input: An array of non-negative integers, where each element in the array represents your maximum jump length at that position. Output: A boolean value if you are able to reach the last index starting if you start at the first spot in the array. [Please write a recursion function!] Example 1: Input: [2,4,1,2,4,1] Output: True (Ex. 0 to 1 to 5 or 0 to 2 to 3 to 5) Example 2: Input: [3,2,1,0,4] Output: false (You will always arrive at,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT