Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

All in java please 1. An array is effectively a collection of related variables of the same type. For example, a collection of grades of

All in java please

1. An array is effectively a collection of related variables of the same type. For example, a collection of grades of students, a collection of salary of employees of a company, etc. In this exercise, you will construct a program that allows a user to enter the height, in inches, of 8 people in a room, determine the average of the heights, and then output the average along with all of the heights. To complete this program: Define an integer constant to keep track of the number of people Define an array to hold all of the heights using the constant Using a loop of your choice, prompt for, read in, and store the height of each person in the array Using a loop of your choice, calculate the average height by iterating through the array Using a loop of your choice, output each of the user provided heights in the array Using a suitable message, output the average height with three decimal points of precision.

2. A two-dimensional array is an array of one-dimensional arrays. For example, int[][] arr_2D = new int[2][5]; is an array with 2 elements which are themselves integer arrays of size 5. It is common to refer to the size of a 2-D array using rows and columns. In this example, arr_2D has 2 rows and 5 columns, and each row is an array of 5 integers. For this exercise, you will need to construct a program that prompts the user for a row and column size for a two-dimensional array, and then create that array. Then your program will need to fill the 2D array with random numbers in the range of 0 to 10, inclusively. You will also need a 1D integer array with 11 slots in which every slot is initialized to 0. Once all of the numbers are stored in the 2D array, go back through the 2D array and use the 1D array to keep track of how frequently each of the numbers between 0 and 10 occur. Be sure to also determine which number(s) represent the mode of the series. (Remember that the mode of a series is the number(s) that occurs most frequently!) Finally, output the 2D array in a grid format and output the mode with an appropriate message. If multiple numbers occur the most frequently (i.e. you have multiple modes), output each of them. (As a hint, think about the relationship between the mode and its frequency.)

3. Sorting data within data structures is a very common, and sometimes very necessary, operation. Not only does it make information easier to parse through for humans, but it can provide benefits when searching through data, as we will see with more complex structures such as trees. For this exercise, you will be sorting a character array into lexicographic order (i.e. ascending alphabetical order). To complete this program you will need to: Define a method that returns an integer and takes in a character array as a parameter and should o Have an integer variable to keep track of the number of iterations through the array it is sorting, initialized to 0 o Iterate through the array, from beginning to end, and any time it detects two characters that are next to each other but are out of order (i.e. the left character has a larger ASCII value than the right character) it should swap them o After an iteration, the method should output the array to show the sorting progression o Repeatedly iterate through the array until all elements are in the correct order o Return the number of iterations required to sort the array In your main method o Define a char array and set its default data to the letters b, f, a, z, m, g, r, x, t, n o Call your sorting method, pass in the char array, and store the methods output in an appropriate variable o Output to the user, with an appropriate message, the newly sorted array along with the number of iterations required to sort it

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Concepts of Database Management

Authors: Philip J. Pratt, Joseph J. Adamski

7th edition

978-1111825911, 1111825912, 978-1133684374, 1133684378, 978-111182591

More Books

Students also viewed these Databases questions

Question

What are the test validation approaches? Define each.

Answered: 1 week ago