Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question 1 (Essay Worth 10 points) Write a method that adds the values of an integer array. Declare an array of integer values that will

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed
Question 1 (Essay Worth 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 the sum at the end of the method.Question 2 (Essay Worth 10 points) The following code segment is part of a bigger program to multiply 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 of doubles (based on the length of al or a2) fill the new array with the product of the corresponding elements in 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: {1.2, 4.6, 10.2, 18.0, 28.0} Complete the code segment to accomplish the additional tasks described.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 right triangles are similar when the measurement of each side is provided as an integer value. If one set of corresponding sides of the triangles have lengths of 18 and 12, the ratio would be 1.5. The method needs to return a String stating if the triangles are similar or not.Question 4 {Essay Worth 10 points) F3 You are an intem 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 retum 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 reoorded 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

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

Transport Operations

Authors: Allen Stuart

2nd Edition

978-0470115398, 0470115394

Students also viewed these Programming questions

Question

How can employee involvement measures motivate employees?

Answered: 1 week ago

Question

What is the value of x in the expression x=2**1*2+1 > 5

Answered: 1 week ago