
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
For Java.
Create a
![In this problem, you will create a program that can read Ninteger numbers, store them in an array and then use a method to calculate and return the average of all numbers. You must create the method and calculate the average of the numbers Inside the
method. The method's signature is as follows:
private static double calculateAverage (int [] numbers)
Your program will implement the following algorithm:
1. Read the value of N.
2. Create an array of size N.
3. Read from the user and store N integers on the array.
4. Call the calculateAverage method and store the result
5. Print the average limited to 3 decimal points using the printf method (%.3f)
Please note: The first test case will ensure that you have the correct method signature. The second test case will test your method isolated from the rest of your program. These two methods are called unit tests and will be the norm from now on.
Example I/O (Test cases 3, 4, 5)
Input
49130
88189 3 12 22 20 11
Output
3.250
20.750](https://content.bartleby.com/qna-images/question/4ff7b463-2271-4806-9568-a63428385e39/cd8ac028-ee06-4a92-b739-a5365a6a7501/ya8aj8v_thumbnail.png)
Transcribed Image Text:In this problem, you will create a program that can read Ninteger numbers, store them in an array and then use a method to calculate and return the average of all numbers. You must create the method and calculate the average of the numbers Inside the
method. The method's signature is as follows:
private static double calculateAverage (int [] numbers)
Your program will implement the following algorithm:
1. Read the value of N.
2. Create an array of size N.
3. Read from the user and store N integers on the array.
4. Call the calculateAverage method and store the result
5. Print the average limited to 3 decimal points using the printf method (%.3f)
Please note: The first test case will ensure that you have the correct method signature. The second test case will test your method isolated from the rest of your program. These two methods are called unit tests and will be the norm from now on.
Example I/O (Test cases 3, 4, 5)
Input
49130
88189 3 12 22 20 11
Output
3.250
20.750
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 2 steps

Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Use Java to write a program that prompts the user for a positive odd integer , generates a normal magic square of order size of that integer, and prints it with numbers right-justified and aligned in evenly-spaced columns. (Magic square definition: https://en.wikipedia.org/wiki/Magic_square. Can assume that the numbers in the square are 3 digits or less (i.e. size ≤ 31). Have the construction of the 2D integer array magic square take place in a public static method getMagicSquare that takes in an integer n as a parameter and returns the 2D integer array magic square as specified. Your main method should perform input and output (I/O) and call this method to perform the computation. Methods for generating a magic square : Assign 1 to our initial current position: the bottom row, middle column. Place each successive value (up to size * size) in the first of the following positions that is unoccupied: (1) one space down and to the right, or (2) one space up. Positions wrap around…arrow_forwardGiven an array below, write a Java program to take input an integer n from the user and print the "True" or "False" depending upon the number n is present twice in the array or not. int [Jarr = {12,-67,13, 15, 12, 15, -67, 0, 1,1}arrow_forwardPlease use java to complete and please do not reject the question it isnt that complex.arrow_forward
- Write the Java method averageOfDoubles that is passed an array of double values, and returns the average of the array values.You can assume the array length is a positive integer.arrow_forwardWrite a method which does the following:a. Ask the user to enter a size of array between 2 to 10.b. Based on the size entered, write a loop which asks the user to fill values into an integer array. Printthe array contents using Arrays.toString().c. For this integer array, write a logic that returns true if there exists a place to split the array such thatthe sum of the numbers on one side is equal to the sum of the numbers on the other. Otherwisereturn false.d. Examples:If the array is {1, 1, 1, 2, 1} then return true.If the array is {2, 1, 1, 2, 1} then return falseIf the array is {10, 10} then return true must include a try catch statementarrow_forwardWrite a Java program to take an array of ints, print the number of 9's in that array.arrow_forward
- i need to make sure for the answer javaarrow_forwardGiven two sorted arrays, your task is to merge them in a new sorted array. Write a complete program in Java that takes two stored arrays of integers, and then calls a method that merges the two sorted arrays into one array that is sorted. The method returns a new array made by merging the two input sorted arrays. Note that the input arrays can be of different sizes. Assume that the size of each input array is given. You can NOT write a sorting algorithm or apply sorting. To clarify: You cannot merge the two arrays into one and then just sort it using a sorting algorithm. Examples: Input : arr1 = { 1, 3, 4, 5} arr2 = {2, 4, 6, 8} Output : arr3 = {1, 2, 3, 4, 5, 6, 7, 8} Input : arr1 = { 5, 8, 9} arr2 = {4, 7} Output : arr3 = {4, 5, 7, 8, 9}arrow_forwardWrite a java program that prompts user for 10 numbers of any type and stores them in an array. Then print the following: All the values in the array. The sum of all values in the array. The average of all values in the array. The largest value in the array. The smallest value in the array. All the positive numbers in array. All the negative numbers in array. All the odd numbers in array. All the even numbers in array.arrow_forward
- Needs to be written in java and completed using "for loops" or "nested for loops" and in one program just seperate methods: Write a program that calls these three methods. method 1 should print: 5 4 3 2 1 4 3 2 1 3 2 1 2 1 1 method 2 should print: 1 2 3 4 5 1 2 3 4 1 2 3 1 2 1 method 3 should create and array and store 10 multiples of 5 and print it out. Use for loop to generate the multiples and then print them out using a second for loop.arrow_forwardUse Java language and the last digit of ID is a 7arrow_forwardCAN THIS PLEASE BE DONE In PYTHON? Input a list of employee names and salaries and store them in parallel arrays. End the input with a sentinel value. The salaries should be floating point numbers Salaries should be input in even hundreds. For example, a salary of 36,510 should be input as 36.5 and a salary of 69,030 should be entered as 69.0. Find the average of all the salaries of the employees. Then find the names and salaries of any employee who's salary is within 5,000 of the average. So if the average is 30,000 and an employee earns 33,000, his/her name would be found. Display the following using proper labels. Save your file using the naming format LASTNAME_FIRSTNAME_M08 FE. Turn in your file by clicking on the Start Here button in the upper right corner of your screen. 1.Display the names and salaries of all the employees. 2. Display the average of all the salaries 3. Display all employees that are within 5,000 range of the average.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education

Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON

Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education