Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(a) Write code segments to perform the following: (i) declare and create an integer array freqArray of size 8 (ii) declare and initialize an array

(a) Write code segments to perform the following:
(i) declare and create an integer array freqArray of size 8
(ii) declare and initialize an array weight (with suitable type) which contains 48.5, 80 and 68
(iii) declare a Mouse array of size 2 with name mouse and initialize it with Mouse objects using one statement
(b) A incomplete definition of a class Temperature is given below:
public class Temperature {
private double value[] = {36.5, 40, 37, 38.3};
}
(i) Copy and put it in a new class. Write a method toString() of the class, which does not have any parameters and returns a string containing all the values separated by newlines. When the string is printed, each value should appear on a line in the ascending order of their indexes. Copy the content of the method as the answers to this part.
(ii) Write another class TestTemperature in a separate file with a method main() to test the class Temperature. In main(), create a Temperature object temperature and print its values by calling toString(). Run the program. Copy the content of the file and the output showing the message as the answers to this part.
(iii) Add a method decreasePercent(int index, double percent) to the Temperature class which decreases the element with subscript index of the value array by the percentage percent without returning anything. Also add a method getValue(int index) to return value[index]. Copy the content of the methods as the answers to this part.
(iv) Add another method countNotLessThan(double threshold) to the Temperature class which returns the number of values which are not less than threshold. Copy the content of the method as the answers to this part.
(v) Add another method minimumIndex() to the Temperature class which returns the index of the minimum value in the array. Copy the content of the method as the answers to this part. You can assume there is only one minimum value.
(vi) Add another method trimmedMean() to the Temperature class which returns the average value which excludes the (unique) largest value and (unique) smallest value in the calculation. You should use minimumIndex() to get the index of the minimum value. Note that this method should work without any modifications when the number of values, which is at least three, is changed. Copy the content of the method as the answers to this part.
(vii) Perform the tasks listed below in main() of TestTemperature:
* print the second value from the left, decrease it by 10% using the method
decreasePercent(), and print the new value;
* calling countNotLessThan()to count the number of values not less than 37 and then
print it;
* print the index of the minimum value and the trimmed mean.
Run the program. Copy the content of the class and the output as the answers to this part.

Step by Step Solution

3.46 Rating (159 Votes )

There are 3 Steps involved in it

Step: 1

Mouse Class public class Mouse int button public Mouse button0 Array Declare Class publ... 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

Quantitative Analysis for Management

Authors: Barry Render, Ralph M. Stair, Michael E. Hanna, Trevor S. Ha

12th edition

133507335, 978-0133507331

More Books

Students also viewed these Programming questions

Question

Eliminate street slang.

Answered: 1 week ago

Question

Explain the various methods of job evaluation

Answered: 1 week ago

Question

Differentiate Personnel Management and Human Resource Management

Answered: 1 week ago

Question

Describe the functions of Human resource management

Answered: 1 week ago

Question

What are the objectives of Human resource planning ?

Answered: 1 week ago

Question

What is crashing, and how is it done by hand?

Answered: 1 week ago