Question: Question 1 (10 points) Write a method that adds the values of an integer array. Declare an array of integer values that will represent the
Question 1 (10 points)
Write a method that adds the values of an integer array. Declare an array of integer values that will represent the first five odd numbers: 1, 3, 5, 7, and 9. Initialize each element of the array with the odd number values shown above. Calculate the sum of the array elements, and store the result in a variable named sum. You must access the array elements to accomplish this. Do not write sum = 1 + 3 + 5 + 7 + 9; or sum = 25; Return thesum at the end of the method. (10 points)
Your answer: Question 2 (10 points)
The following code segment is part of a bigger program to multiply the corresponding values of two arrays, a1 and a2. Arrays a1 and a2 are declared and initialized to store a certain number of doubles. public static void newArray() {double[ ] a1 = 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 a1 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 of doubles (based on the length of a1 or a2)
- fill the new array with the product of the corresponding elements in a1 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: {1.2, 4.6, 10.2, 18.0, 28.0} Complete the code segment to accomplish the additional tasks described. (10 points)Your answer: Question 3 (10 points)
int side1; 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. (10 points)
Your answer: Question 4 (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 program 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
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
