To write the Java programs that use methods and arrays. Problem 1: Complete the following java...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
To write the Java programs that use methods and arrays. Problem 1: Complete the following java program which creates an array of 20 elements. The program then should do the following: 1. Initialize the elements of the array to random numbers between 0 and 100. 2. Display the content of the array (i.c., 20 random numbers). 3. Display the smallest number in the array. 4. Display the smallest number in the array. 5. Calculate and display the average of all the numbers. 6. Reverse the array and display it (Do not use a second array to reverse the array, only reuse a temporary variable) public class ArrayDemo { public static void main(String[] args) { int[] numbers = new int[20]; initializeArray (numbers) System.out.println("The array of random numbers is:"); displayArray (numbers); " System.out.println("The smallest number in the array is + getSmallest (numbers)); System.out.println("The average of the array elements is " + getAverage (numbers)); System.out.println("The number of elements above average is + countAboveAverage (numbers)); reverseArray (numbers); System.out.println("The array of random numbers in reverse is:"); displayArray (numbers); Sample Outputs: The array of random numbers is: 86 25 28 60 15 78 86 81 68 The smallest number in the array is 15 The average of the array elements is 56.4 The number of elements above average is 12. The array of random numbers in reverse is: 39 91 74 76 66 37 87 30 68 The array of random numbers is: 61 7 61 91 39 17 47 34 The smallest number in the array is 1 The average of the array elements is 47.0 The number of elements above average is 9 The array of random numbers in reverse is: 21 1 86 6 17 83 74 79 84 The array of random numbers is: 65 11 9 89 99 69 25 Hand In: • 21 20 60 30 87 37 66 76 20 21 68 81 86 78 15 73 34 84 79 74 83 17 6 34 73 25 34 47 17 39 The array of random numbers in reverse is: 25 58 62 94 47 17 3 76 69 64 27 83 65 40 69 99 74 91 39 60 28 25 86 86 1 21 40 65 83 27 64 69 76 3 17 47 94 62 58 25 The smallest number in the array is 3 The average of the array elements is 53.6 The number of elements above average is 12 91 61 7 61 11 65 Make a folder named lab6_yourname containing the source code file, zip the folder and submit the zipped file to BrightSpace. Rubrics: Program: • [2 marks] Presentation and Style: Readability, descriptive identifier, indentation, bracket placement, internal documentation (comments), use of appropriate constants • [18 marks] Correctness: Program works without bugs To write the Java programs that use methods and arrays. Problem 1: Complete the following java program which creates an array of 20 elements. The program then should do the following: 1. Initialize the elements of the array to random numbers between 0 and 100. 2. Display the content of the array (i.c., 20 random numbers). 3. Display the smallest number in the array. 4. Display the smallest number in the array. 5. Calculate and display the average of all the numbers. 6. Reverse the array and display it (Do not use a second array to reverse the array, only reuse a temporary variable) public class ArrayDemo { public static void main(String[] args) { int[] numbers = new int[20]; initializeArray (numbers) System.out.println("The array of random numbers is:"); displayArray (numbers); " System.out.println("The smallest number in the array is + getSmallest (numbers)); System.out.println("The average of the array elements is " + getAverage (numbers)); System.out.println("The number of elements above average is + countAboveAverage (numbers)); reverseArray (numbers); System.out.println("The array of random numbers in reverse is:"); displayArray (numbers); Sample Outputs: The array of random numbers is: 86 25 28 60 15 78 86 81 68 The smallest number in the array is 15 The average of the array elements is 56.4 The number of elements above average is 12. The array of random numbers in reverse is: 39 91 74 76 66 37 87 30 68 The array of random numbers is: 61 7 61 91 39 17 47 34 The smallest number in the array is 1 The average of the array elements is 47.0 The number of elements above average is 9 The array of random numbers in reverse is: 21 1 86 6 17 83 74 79 84 The array of random numbers is: 65 11 9 89 99 69 25 Hand In: • 21 20 60 30 87 37 66 76 20 21 68 81 86 78 15 73 34 84 79 74 83 17 6 34 73 25 34 47 17 39 The array of random numbers in reverse is: 25 58 62 94 47 17 3 76 69 64 27 83 65 40 69 99 74 91 39 60 28 25 86 86 1 21 40 65 83 27 64 69 76 3 17 47 94 62 58 25 The smallest number in the array is 3 The average of the array elements is 53.6 The number of elements above average is 12 91 61 7 61 11 65 Make a folder named lab6_yourname containing the source code file, zip the folder and submit the zipped file to BrightSpace. Rubrics: Program: • [2 marks] Presentation and Style: Readability, descriptive identifier, indentation, bracket placement, internal documentation (comments), use of appropriate constants • [18 marks] Correctness: Program works without bugs
Expert Answer:
Answer rating: 100% (QA)
Program import javautil public class ArrayDemo generate 20 random elements public static void initializeArrayint numbers Random r new Random int low 1 ... View the full answer
Related Book For
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill
Posted Date:
Students also viewed these programming questions
-
Program :1 FlashCard This program implements a flash card to teach multiplication. Write a program that uses a WidgetView object (the WidgetView class is available elsewhere in this Lesson). your...
-
This assignment reviews object-oriented programming concepts such as classes, methods, constructors, accessor methods, and access modifiers. It makes use of an array of objects as a class data...
-
The lab requires you to create two files patientAccount.cpp and accountDriver.cpp. You will end up with patientAccount.h, patientAccount.cpp and accountDriver.cpp. (50%) PatientAccount Class...
-
What kinds of functions of local government are usually protected by immunity?
-
An inductor has a reactance of 100 at 80 Hz. (a) What is its inductance? (b) What is its reactance at 160 Hz?
-
Costs of Financial Distress Steinberg plc and Dietrich plc are identical firms except that Dietrich is more levered. Both companies will remain in business for one more year. The companies economists...
-
James Lewis, a resident of Kentucky, sustained an injury while operating a Caterpillar bulldozer. He filed suit against Caterpillar, a company incorporated in Delaware but with its principal place of...
-
Leno Company manufactures toasters. For the first 8 months of 2014, the company reported the following operating results while operating at 75% of plant capacity: Sales (350,000 units) .......
-
2. A plain concrete cylinder with dimensions of 12" height and 6" diameter is tested using spilt tension test. The failure load was measured to be 70 kN. What is the indirect tensile strength of...
-
The information listed below refers to the employees of Lemonica Company for the year ended December 31, 2016. The wages are separated into the quarters in which they were paid to the individual...
-
All students will post to a central "board" and respond. (See below) Project 4.1s purpose is to help you understand the problems parties face with oral or written contracts under the Statute of...
-
What should you as a solicitor specialising in media law advise your media client to do if it wishes to expand its operations from simply television broadcasting to local radio as well as,...
-
A defendant is believed by many to be guilty of child Which of the following is one of the 3 media stereotypes of professional law enforcement created by the media? of the following is one of the 3...
-
Discuss and interpret the nature of copyright in a world of social media. Consider whether law protects (or should protect) the copyright of individuals on social media. ?
-
Explain how and why social media is being used by law enforcement. Also discuss the problems that may result from the adoption of social media by law enforcement agencies.?
-
Need news article describing a legal issue dealing with media or mediated communication (e.g., the internet, social media, communication law). Summarize the article and indicate which source of law...
-
Consider an economy with two consumers whose preferences are represented by utility functions U = min{21, 31} and U = 2x2 + y2 and the aggregate endowment of 4 units of r and 3 units of y. (a) (3)...
-
Quality Chicken grows and processes chickens. Each chicken is disassembled into five main parts. Information pertaining to production in July 2012 is: Joint cost of production in July 2012 was $50. A...
-
Quince Interests is a partnership with a tax year that ends September 30, 2012. During that year, Potter, a partner, received $3,000 per month as a guaranteed payment, and his share of partnership...
-
Mary paid $2,000 of state income taxes in 2012. The total sales tax she paid during 2012 was $5,500, which included $3,000 for the cost of a new car. How should Mary treat the taxes paid on her 2012...
-
During 2012, William purchases the following capital assets for use in his catering business: New passenger automobile (September 30)........................$21,500 Baking equipment (June 30)...
-
Show that for a gas of noninteracting bosons, or fermions, the pair correlation function \(g(r)\) is given by the expression \[g(r)=1 \pm \frac{g_{s}}{n^{2} h^{6}}\left|\int_{-\infty}^{\infty}...
-
Show that, in the case of a degenerate gas of fermions \(\left(T \ll T_{F} ight)\), the correlation function \(g(r)\), for \(r \gg \hbar / p_{F}\), reduces to the expression \[g(r)-1=-\frac{3(m k...
-
Show that the pressure and Helmholtz free energy of a fluid at temperature \(T\) can be determined by performing a thermodynamic integration of the inverse of the isothermal compressibility from the...
Study smarter with the SolutionInn App