Implement a method addData(double val) in the class below. public class MyArray { private double data[];...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Implement a method addData(double val) in the class below. public class MyArray { private double data[]; } If an element of data matches the value, the array data remain the same. The method returns -1. Otherwise, reset the array data with one more element. Add the new value as the last element of the reset array. Return the index of the new value in the array data. Assume the array data initialized as data = new double[] {1.5, 1.2, 3.7, 4.8, 2.2, 5.3, 1.1, 2.3}; When calling the method addData(2.5), it returns 8. The elements in the updated array data are: {1.5, 1.2, 3.7, 4.8, 2.2, 5.3, 1.1, 2.3, 2.5} When calling the method addData(2.2), it returns -1. The elements are not changed. They are {1.5, 1.2, 3.7, 4.8, 2.2, 5.3, 1.1, 2.3} Implement a method addData(double val) in the class below. public class MyArray { private double data[]; } If an element of data matches the value, the array data remain the same. The method returns -1. Otherwise, reset the array data with one more element. Add the new value as the last element of the reset array. Return the index of the new value in the array data. Assume the array data initialized as data = new double[] {1.5, 1.2, 3.7, 4.8, 2.2, 5.3, 1.1, 2.3}; When calling the method addData(2.5), it returns 8. The elements in the updated array data are: {1.5, 1.2, 3.7, 4.8, 2.2, 5.3, 1.1, 2.3, 2.5} When calling the method addData(2.2), it returns -1. The elements are not changed. They are {1.5, 1.2, 3.7, 4.8, 2.2, 5.3, 1.1, 2.3}
Expert Answer:
Answer rating: 100% (QA)
Here is the implementation of the addData method based on the provided requirements public class MyA... View the full answer
Related Book For
Java How To Program Late Objects Version
ISBN: 9780136123712
8th Edition
Authors: Paul Deitel, Deitel & Associates
Posted Date:
Students also viewed these programming questions
-
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...
-
Let A, B be sets. Define: (a) the Cartesian product (A B) (b) the set of relations R between A and B (c) the identity relation A on the set A [3 marks] Suppose S, T are relations between A and B, and...
-
South Sea Baubles has the following (incomplete) balance sheet and income statement. a. What is shareholders' equity in 2013 and 2014? b. What is net working capital in 2013 and 2014? c. What are...
-
Does the fact that your bank keeps only a fraction of your account balance in reserve worry you? Why don't people rush to the bank and retrieve their money? What would happen if they did?
-
A 2500-kg block is suspended by two ropes, as shown. Find the tension in each rope. 45 2500 kg 60
-
Consider the following cash flow profile and assume MARR is 10 percent/year. a. Determine the IRR(s) for this project. b. Is this project economically attractive? EOY 0 1 2 3 4 5 6 NCF -$101 $411...
-
Direct labor variances: price, efficiency, mix, and yield. Trevor Joseph employs two workers in his guitar-making business. The first worker, George, has been making guitars for 20 years and is paid...
-
A small electric immersion heater is used to heat 87 g of water for a cup of instant coffee. The heater is labeled "120 watts" (it converts electrical energy to thermal energy at this rate)....
-
After the dot-com business he tried to start folded, David "Marty" Dawkins decided to pursue his boyhood dream of owning a bike factory. After several false starts, he finally got the small company...
-
A company that produces and sells 4,000 units per month, with the capacity to produce 5,000 units per month. is evaluating a one-time, special order for 2,000 units from a large chain store....
-
If you are coasting 8m/s, and you slow down to 6.5m/s after 7.2m of decelleratin, what was your acceleration when you were in the 7.2 m section
-
Suppose the risk-free rate is 5.00% and the market portfolio has an expected return of 13.50%. A portfolio is invested equally in three securities with betas of 0.60, 1.35, and 1.40 respectively....
-
An astronaut has landed on an unknown planet. She drops a wrench from a height of 8.61 meters above the surface. The wrench takes 7.11 seconds to fall to the surface. What is the acceleration of...
-
Could you provide an elucidation of the concept of a pay-back contract? Additionally, could you furnish an example utilizing a real-life company to illustrate this concept?
-
Accurate Builders construction company was incorporated by John Davis. Assume the following activities occurred during the year: a. Received from three investors $54,000 cash and land valued at...
-
Masma Corp. began operations in 2020. An analysis of Masma's equity securities portfolio acquired in 2020 shows the following totals at the end of the year. Masma accounts for these investments using...
-
United Business Forms capital structure is as follows: Debt ............................................ 35% Preferred stock ........................... 15 Common equity .......................... 50...
-
Explain why a Java program might use the statement List workerList = new ArrayList ();
-
The formulas for calculating the BMI are Create a BMI calculator app that allows users to enter their weight and height and whether they are entering these values in English or metric units, then...
-
Fill in the blanks in each of the following statements: a. Stream are formed from stream sources, intermediate operations and termi- nal operations. b. The following code uses the technique of...
-
Are the initial rates lower on a fixed-rate loan or a variable-rate loan? Why?
-
Why are mortgage payments not included in the debt limit ratio?
-
Visit the Consumer Financial Protection Bureau Web site (www.consumerfinance.gov). Based on the public information available, describe what role the bureau plays in providing consumer education,...
Study smarter with the SolutionInn App