Concept explainers
(Average an array) Write two overloaded methods that return the average of an array with the following headers:
public static int average(int[] array)
public static double average(double[] array)
Write a test
Want to see the full answer?
Check out a sample textbook solutionChapter 7 Solutions
Introduction to Java Programming and Data Structures Comprehensive Version (11th Edition)
Additional Engineering Textbook Solutions
INTERNATIONAL EDITION---Engineering Mechanics: Statics, 14th edition (SI unit)
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
Starting Out with Python (4th Edition)
Degarmo's Materials And Processes In Manufacturing
Concepts Of Programming Languages
Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
- Description: Write a method that return the average of an array with the following header: public static double average(double[] array); In the main method, 5 double numbers are required to be entered. Input Example: 1.2 1.2 1.3 1.3 1.35 Output Example: The average value is 1.27arrow_forwardRetailItem Class Write a class named Retailltem that holds data about an item in a retail store. The class should have the following fields: • description. The description field references a String object that holds a brief description of the item. • unitsOnHand. The unitsOnHand field is an int variable that holds the number of units currently in inventory. • price. The price field is a double that holds the item's retail price. Write a constructor that accepts arguments for each field, appropriate mutator methods that store values in these fields, and accessor methods that return the values in these fields. Once you have written the class, write a separate program that creates three RetailItem objects and stores the following data in them: Description Units on Hand Price Item #1 Jacket 12 59.95 Irem #2 Designer Jeans 34.95 [rem #3 Shirt 24.95arrow_forwardWrite the following methodthat tests whether the array has four consecutive numbers with the same value:public static boolean isConsecutiveFour(int[] values)Write a test program that prompts the user to enter a series of integers and displaysit if the series contains four consecutive numbers with the same value. Yourprogram should first prompt the user to enter the input size—i.e., the number ofvalues in the series. Here are sample runs: Enter the number of values: 8↵EnterEnter the values: 3 4 5 5 5 5 4 5↵EnterThe list has consecutive foursEnter the number of values: 9↵EnterEnter the values: 3 4 5 5 6 5 5 4 5↵EnterThe list has no consecutive foursarrow_forward
- Using Java: (Sum the areas of geometric objects) Write a method that sums the areas of all thegeometric objects in an array. The method signature is:public static double sumArea(GeometricObject[] a) Write a test program that creates an array of four objects (two circles and tworectangles) and computes their total area using the sumArea methodarrow_forwardUsing Java Eclipse IDE (Average an array) Write two overloaded methods that return the average of an array with the following headers: public static int average(int [] array) public static double average(double [] array) Write a test program that prompts the user to enter 10 double values, invokes this method, then displays the average value.arrow_forwardPlease help me with this , I am stuck ! thanks 1) bagUnion: The union of two bags is a new bag containing the combined contents of the original two bags. Design and specify a method union for the ArrayBag that returns as a new bag the union of the bag receiving the call to the method and the bag that is the method's parameter. The method signature (which should appear in the .h file and be implemented in the .cpp file is: ArrayBag<T> bagUnion(const ArrayBag<T> &otherBag) const; This method would be called in main() with: ArrayBag<int> bag1u2 = bag1.bagUnion(bag2); Note that the union of two bags might contain duplicate items. For example, if object x occurs five times in one bag and twice in another, the union of these bags contains x seven times. The union does not affect the contents of the original bags. Here is the all of the file: ArrayBag.cpp: #include <string>#include "ArrayBag.h" template <class T>ArrayBag<T>::ArrayBag() :…arrow_forward
- Write a program to accomplish the following tasks:- a) Write a method to print the ArrayList in the reverse order b) Write a method to sort the ArrayList, and display the data after sorting c) Write a method to print the largest and the smallest element in the ArrayList d) In the main method ask user to enter 10 integers, store them in the ArrayList, pass the ArrayList to above methods, and then display the result after each call.arrow_forwardIndicate true or false for the following statements: Every element in an array has the same type. The array size is fixed after it is declared. The array size declarator must be a constant expression. The array elements are initialized when an array is declared.arrow_forwardWrite method body of following methods: InsertNum(int num) // The function takes a number from user as input and it is intelligent enough to place the number at desired index of an array. For example if array has values from 1,3,5,7 and user entered 6 so the function will place 6 after 5 and before 7. (Use While Loop) InsertNum(int num,int position) // This function takes number and position from user and then place the number at desired position of array. Remember to ask from user if there is already a number at that position. (Code in C++)arrow_forward
- Using Javaarrow_forwardTASK 1 Write a Java method that returns the index of the smallest element in an array of integers. If the number of such elements is greater than 1, return the smallest index. Use the following header: public static int indexofLargestlestelement(double[] array) Write a test program that prompts the user to enter ten numbers, invokes this method to return the index of the smallest element, and displays the index.arrow_forward1. write a method that receives a character array and returns the number of symbols in the arrayarrow_forward
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage