Question

In: Computer Science

Complete answer will be given an immediate upvote :) 1. Explain the rationale for returning a...

Complete answer will be given an immediate upvote :)

1. Explain the rationale for returning a Boolean value from the add bag operation.

2. Explain why writing a test program before implementing a class is a good idea.

3. Why is it a safer practive for the toArray method to return a copy of the array instead of a reference to the array?

Solutions

Expert Solution

1) This originates from Collection <E> prefix, because the interface is used as the ancestral component of all types of clusters, it makes sense to return the boolean notification when adding a cluster to a successful operation.

2) This is called the test-driven approach. It is recommended to avoid errors and bugs in a program. To understand this, imagine 2 cases.

Case 1 : When u write a program first (i.e implementing a class) and then test its functions - While working on a big project with multiple objective you might forget implementing a task over the time. projects can go for a long time even months to complete and thus it might happen that a programmer might forget to insert those features. If he forgets, it is detectec during the testing phase by testers and will fail in production.

Case 2 : When you write test cases first and then implement a class, the programmer makes sure test cases of all requirements are already mentioned. This helps the programmer identify any bugs, errors or mistakes before it goes into production.

Thus it is recommended to use the test-driven approach.

3) It can be very inconsistent for changes in the returned array to affect the source at times and sometimes not. ToArray works the same way for the same reason. Thus, you will always get a copy of the array instead of the same reference to it to avoid the confusion of changes in the orignal array and its address.


Related Solutions

Please answer this question with explanation. I will upvote your answer if it is correct and...
Please answer this question with explanation. I will upvote your answer if it is correct and clear. Thank you! You are given a positive integer n of the form n = 2h − 1, for some integer h ≥ 1. Give an example of an array of length n where the following method of building a heap step 1. Place the new key at the first free leaf step 2. The heap-order property might be violated: perform a bubble-up, uses...
Select one answer in the given questions. No need to give rationale. Q2: An advantage to...
Select one answer in the given questions. No need to give rationale. Q2: An advantage to using a three-part diagnostic statement in the PES format is that such as statement: Choices: A. applies to risk and wellness diagnosis B. documents the indicators of the problem C. is shorter D. is always more accurate Q6: Impaired skin integrity related to not being repositioned for every two hours is an incorrect nursing diagnosis due to which of the following best reason? Choices:...
could you answer all of these and leave details. I will upvote thanks! 1- What is...
could you answer all of these and leave details. I will upvote thanks! 1- What is CPI? 2- What is the CPU execution time? 3- What do KB, MB, and GB mean? Which power of 2 are they? 4- What’s the difference between bit and byte? 5- What is the CPU execution time for a program made of 20000 instructions and a CPI equal to 2. Assume the frequency of the processor is 3 GHz. 6- A microprocessor has 20...
rationale for each steps taken to complete the task
rationale for each steps taken to complete the task
Discuss the rationale for your answer.
Which of the two common approaches used to account for by-product/scrap provides better information to management? Discuss the rationale for your answer.
could you answer all of these and leave details. I will upvote thanks! 1- How does...
could you answer all of these and leave details. I will upvote thanks! 1- How does the machine code differ form the assembly language? 2- What is an opcode? What is an operand? What is the function of an assembler? 3- What are the programming languages categories? 4- Specify the addressing mode in each case below: a) ADD AX, [1200H] b) MOV BX, DX c) SUB [1000H]+ BX, AX d) MOV AL, SI+ [3300H] e) ADC AX, 25H 5- What...
Multiple choice with rationale. Choose the letter of the correct answer and explain briefly why that...
Multiple choice with rationale. Choose the letter of the correct answer and explain briefly why that is the correct answer and why the other choices are incorrect. What modification in the Pol II enzyme leads to elongation of the polynucleotide chain? A. Acetylation B. Dephosphorylation C. Glucuronidation D. Phosphorylation 20. Which of the following molecular component/s are observed in the termination phase of protein synthesis? A. Amino acids, ATP B. Release factors, GTP C. Shine- Dalgarno sequence D. Aminoacyl-tRNA synthetase
Please answer as soon as possible, I will upvote if it is answered in 40 minutes....
Please answer as soon as possible, I will upvote if it is answered in 40 minutes. Suppose that a bond portfolio with a duration of 5 years is hedged using a futures contract in which the underlying asset has a duration of 14 years. What is likely to be the impact on the hedge of the fact that the 14-year rate is less volatile than the 5-year rate?
1) Answer the folowing in complete sentences. A) Describe, explain, and discuss the portfolio effect and...
1) Answer the folowing in complete sentences. A) Describe, explain, and discuss the portfolio effect and portfolio consideration when evaluating risk B) Explain and discuss Market Efficiency as it relates to capital markets. Why is it important?
a.) Describe an outcome that would result in a Type I error. Explain the rationale for your answer.
Two types of medication for hives are being tested. The manufacturer claims that the new medication B is more effective than the standard medication A and undertakes a comparison to determine if medication B produces relief for a higher proportion of adult patients within a 30-minute time window. 20 out of a random sample of 200 adults given medication A still had hives 30 minutes after taking the medication. 12 out of another random sample of 200 adults given medication...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT