Question: Question 2 (Essay Worth 10 points) The following code segment is part of a bigger program to add the corresponding values of two arrays, al




Question 2 (Essay Worth 10 points) The following code segment is part of a bigger program to add the corresponding values of two arrays, al and a2. Arrays al and a2 are declared and initialized to store a certain number of doubles. public static void newArray () { double [ ] al = new double [some length] ; double [ ] a2 = new double [some length] ; // Assume that there is code here that prompts the user to enter these double // values and stores them in al and a2. You don't know what the user will type, but // you may assume that the code is correct and no errors occur in this portion of the program. // Complete this part of the method Add code to do the following: . declare an additional array of doubles (based on the length of al or a2) . fill the new array with the sum between the corresponding elements al and a2 print the values stored in the new array to the screen For example, if the first two arrays hold the following values: (1.2, 2.3, 3.4, 4.5, 5.6) and (1.0, 2.0, 3.0, 4.0, 5.0}, your array should be filled with the following values: (2.2, 4.3, 6.4, 8.5, 10.6} Complete the code segment to accomplish the additional tasks described. X 8 + 2 8 0 % Source V C BIUSXX IX 13 : " = = = |Styles . Format Font - Size - A- A - ?Question 1 (Essay Worth 10 points) Write a method to calculate and return the sum of the values in an array. Declare an array of integer values that will represent the first five prime numbers: 2, 3, 5, 7, and 11. Initialize each element of the array with the prime number values shown above. Calculate the sum of the array elements, and store the result in a variable named total. You must access the array elements to accomplish this. Do not write total = 2 + 3 + 5 + 7 + 11; or total = 28; Return the total at the end of the method. * + 6 8 0 % Source VC BIUSXXX:"BEE Styles Format . Font - Size - A- A - ?Question 3 (Essay Worth 10 points) int sidel; int side2; //additional vars as needed /*assume there is code here to initialize these values*/ Two polygons are said to be similar if their corresponding angles are the same or if each pair of corresponding sides has the same ratio. Write a method to test if two rectangles are similar when the length and width of each are provided as integer values. If the rectangles have lengths of 10 and 8, the ratio would be 1.25. The method needs to return a String stating if the rectangles are similar or not. Q Source V C BIUS XXX : " BEE Styles - Format . Font - Size - AA- ?Question 4 (Essay Worth 10 points) You are an intern at a local animal sanctuary. One of your tasks is to record how many pounds of bamboo the pandas consume daily for 10 days. Write a method to calculate and return the average weight based on the data. Before calculating the average, you decide to throw out the lowest and highest values. Your method should do the following: declare and initialize the array with the recorded weights such as 43.1 determine the maximum and minimum values in the array . compute the average of the array contents, excluding the maximum and minimum values (array methods may not be used) . calculate and return the average, excluding the maximum and minimum values Complete your code below: = = Q X D Source V C BIUS X X2 XX 1 :(1 9) = = = |Styles Format . Font - Size . A- A
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
