Question 3.1 Create a class containing a method name createArray and a main method. The method...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Question 3.1 Create a class containing a method name createArray and a main method. The method createArray creates an array where each element contains the square of its index. The size of the array is determined by the method's parameter. createArray then returns this array. The main methods calls createArray with the right parameter to get the squares of the numbers from 0 to 12, it then prints the values of the array. public class Q3_SquareArray{ public static int[] createArray(int size) { } // Your code here public static void main(String[] args) { // Your code here } |} The output should be similar to this: The output should be similar to this: The square of 0 is: 0 The square of 1 is: 1 The square of 2 is: 4 The square of 3 is: 9 The square of 4 is: 16 The square of 5 is: 25 The square of 6 is: 36 The square of 7 is: 49 The square of 8 is: 64 The square of 9 is: 81 The square of 10 is: 100 The square of 11 is: 121 The square of 12 is: 144 Question 3.2 Complete this code so that it calculates the average of the 7 numbers passed via the array valuesArray: public class Q3_AverageDemo{ public static void main(String[] args) { } double[] valuesArray; valuesArray = new double[]{100.0,34.0, 72.0,56.0,82.0,67.0,94.0}; System.out.println("The average is: + calculate Average (valuesArray)); //method that calculates the average of the numbers in an array public static double calculateAverage (double[] values) { double result; //your code here return result; } Question 3.3 Create a method that inserts an element to a specific index of an array. This method has three parameters: an array, an index and a number to insert. Use the main method to print the array before and after the insertion. (Hint: arrays have fixed size; you must create a second array that is bigger than the first) public class Q3_ArrayInsertionDemo{ public static int[] insert IntoArray(int[] beforeArray, int indexToInsert, int val // Your code here } public static void main(String[] args) { } // Your code here Example of the output: Array before insertion: 1 5 7 9 96 6 Array after insertion of 15 at position 3: 1 5 5 4 15 7 9 6 Question 3.4 Complete this code so that it prints the letters from the char array unordered Letter in decreasing order: public class Q3_ReverseSortDemo { public static void main(String[] args) { } char[] unordered Letters; unordered Letters = new char[]{'b', 'm', 'z', 'a', 'u'}; reverseSort (unordered Letters); for (int i = 0; i < unordered Letters.length; i++ ) System.out.print (unordered Letters[i]); //method that sorts a char array into its reverse alphabetical order public static void reverseSort (char[] values) { //your code here } } Question 3.1 Create a class containing a method name createArray and a main method. The method createArray creates an array where each element contains the square of its index. The size of the array is determined by the method's parameter. createArray then returns this array. The main methods calls createArray with the right parameter to get the squares of the numbers from 0 to 12, it then prints the values of the array. public class Q3_SquareArray{ public static int[] createArray(int size) { } // Your code here public static void main(String[] args) { // Your code here } |} The output should be similar to this: The output should be similar to this: The square of 0 is: 0 The square of 1 is: 1 The square of 2 is: 4 The square of 3 is: 9 The square of 4 is: 16 The square of 5 is: 25 The square of 6 is: 36 The square of 7 is: 49 The square of 8 is: 64 The square of 9 is: 81 The square of 10 is: 100 The square of 11 is: 121 The square of 12 is: 144 Question 3.2 Complete this code so that it calculates the average of the 7 numbers passed via the array valuesArray: public class Q3_AverageDemo{ public static void main(String[] args) { } double[] valuesArray; valuesArray = new double[]{100.0,34.0, 72.0,56.0,82.0,67.0,94.0}; System.out.println("The average is: + calculate Average (valuesArray)); //method that calculates the average of the numbers in an array public static double calculateAverage (double[] values) { double result; //your code here return result; } Question 3.3 Create a method that inserts an element to a specific index of an array. This method has three parameters: an array, an index and a number to insert. Use the main method to print the array before and after the insertion. (Hint: arrays have fixed size; you must create a second array that is bigger than the first) public class Q3_ArrayInsertionDemo{ public static int[] insert IntoArray(int[] beforeArray, int indexToInsert, int val // Your code here } public static void main(String[] args) { } // Your code here Example of the output: Array before insertion: 1 5 7 9 96 6 Array after insertion of 15 at position 3: 1 5 5 4 15 7 9 6 Question 3.4 Complete this code so that it prints the letters from the char array unordered Letter in decreasing order: public class Q3_ReverseSortDemo { public static void main(String[] args) { } char[] unordered Letters; unordered Letters = new char[]{'b', 'm', 'z', 'a', 'u'}; reverseSort (unordered Letters); for (int i = 0; i < unordered Letters.length; i++ ) System.out.print (unordered Letters[i]); //method that sorts a char array into its reverse alphabetical order public static void reverseSort (char[] values) { //your code here } }
Expert Answer:
Related Book For
Data Structures and Algorithms in Java
ISBN: 978-1118771334
6th edition
Authors: Michael T. Goodrich, Roberto Tamassia, Michael H. Goldwasser
Posted Date:
Students also viewed these programming questions
-
CANMNMM January of this year. (a) Each item will be held in a record. Describe all the data structures that must refer to these records to implement the required functionality. Describe all the...
-
answer the question clearly You are building a flight-control system for which a convincing safety case must be made. Would you assign the tasks of safety requirements engineering, test case...
-
The MLC Corporation produces electronic microwave ovens and uses a perpetual inventory system. Its job costing records yield the following information. Job No. 1 m 2 3 4 *5 6 7 Date Finished Sold...
-
The pH of a 0.30 M solution of a weak base is 10.66. What is the Kb of the base?
-
1. Develop a spreadsheet model that Beverly can use to easily update the product mix for other months with different numbers of working days. 2. Use the model to determine how many FTE staff are...
-
a. Which states of a hydrogen atom can be excited by a collision with an electron with kinetic energy \(K=12.5 \mathrm{eV}\) ? Explain. b. After the collision the atom is not in its ground state....
-
R-P Packaging manufactured cellophane wrapping material that was used by Kerns Bakery in packaging its product. Kerns decided to change its system for packaging cookies from a tied bread bag to a...
-
What are the reasons for career plateau which can happen to anyone who starts to feel trapped in their job?(b)Suggest how one can overcome such problem?
-
10-18. Determine the moment of inertia for the area about the y axis. y h y = 6343 Prob. 10-18 h x
-
Use the cross - tabulation tool and any other features in Excel to investigate and report on the gender diversity of the employees across the organisation as a whole and in its six functions. What...
-
Percy Jackson is an independent pen salesman. He's patented a new model, which he calls Riptide, that is supposed to be the best ballpoint pen on the market. Percy will initially invest $84,000 in...
-
1. make three liberal documents designed to protect human rights 2. List and explain the impact of two factors that contributed to the Great Depression 3.List and explain 3 characteristics of a...
-
Discuss your usual listening styles. Under what circumstances you apply those different listening styles? 2. How are those listening styles become beneficial to you? How about its disadvantages? 3....
-
Discuss the pay structure recommendations given by Nutriment Biotech's human resource manager, Jack Stewart. This discussion will prepare for an upcoming meeting with Nutriment Biotech's owners to...
-
What are some factors that can influence each of these components and how for the following: 1. Risk free rate 2. Inflation premium 3. Default risk premium 4. Liquidity premium 5. Maturity risk...
-
1. Below is depicted a graph G constructed by joining two opposite vertices of C12. Some authors call this a "theta graph" because it resembles the Greek letter 0. a. What is the total degree of this...
-
Compute the average return on assets and average margin over borrowing cost using the income statements in Table 7.13 and balance sheets in 7.14. Base on these values is borrowing profitable? Table...
-
Using the data in Tables 7.13 and 7.14, does this farm qualify for debt (i.e., is the farm profitable, liquid, and solvent)? Table 7.13 Table 7.14 Item 2006 2007 2008 2009 2010 2011 2012 Gross cash...
-
The book basis of depreciable assets for Erwin Co. is 900,000 and the tax basis is 700,000 at the end of 2015. The enacted tax rate is 34% for all periods. Determine the amount of deferred taxes to...
Study smarter with the SolutionInn App