Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Computer Engineering Expert

Problem: implement the method and constructor with added requirements

addAll( ) : adjust the type of the parameter, it is an ArrayBag with the same generic type parameter; the method checks if the parameter bag is null or the array field of the parameter is empty, in either case send a message "Nothing was added to the bag" to the console and return the method; otherwise, use the code deemed as wrong implementation on page 142: find a small modification to avoid the trap of an infinite loop as we discussed in class. Do not use the arraycopy method!

Here is my code so far...having issues with dealing with the inifinte loop, for example suppose we have a bag 'b' and activate it with b.addAll(b).

Then the private instance variable 'manyItems' is the same as addend.manyItems. Each iteration of the loop adds 1 to manyItems; so addend.manyItems is also increasing making an infinite loop

public void addAll(ArrayBag addend)
{

if (addend == null){
throw new IllegalArgumentException("The bag is empty.");
}
else{
int i;

ensureCapacity(manyItems + addend.manyItems);
for (i = 0; i < addend.manyItems; i++){
add(addend.data[i]);
}
}

code of ensure capacity method...probably irrelevant, but just to be sure...

public void ensureCapacity(int cap)
{
if(cap <= data.length)
return;
T[] longer = (T[]) new Object[cap];
System.arraycopy(data, 0, longer, 0, manyItems);
data = longer;

}

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M93092452

Have any Question?


Related Questions in Computer Engineering

Explain why a u s recession that occurs as the rest of the

Explain why a U. S. recession that occurs as the rest of the world is expanding will tend to reduce the U. S. Trade deficit.

The relations given below are part of a database schema for

The relations given below are part of a database schema for a hotel management system. Assume that these relations have been populated with suitable data as appropriate, and the underlined attribute is a primary key. Hot ...

Question summary of what is legal and regulatory

Question : Summary of what is legal and regulatory obligations regarding data and information security. Summary of project initiation in the technology world.

Decision support systemsnbspvary greatly in application and

Decision support systems  vary greatly in application and complexity, but they all share specific features. A typical Decision support systems has four components: data management, model management, knowledge management ...

Question a security system is used to monitor doors and

Question : A security system is used to monitor doors and windows of a residence. This system uses several components, including photodiodes and contact switches to detect intruders. Circuits associated with contact swit ...

You are starting a company on a tight budget you can get

You are starting a company on a tight budget. You can get DSL line to your office with a static IP address, but ISP does not offer any DNS services. At this point you do not want to set up your own DNS, so you want to fi ...

The rate of inflation in year 1 is expected to be 14 year

The rate of inflation in year 1 is expected to be 1.4%, year two is 1.8%, and years three through five is expected to be 2%. Assume the real risk-free rate, r*, is 3% for all maturities. What should the yield to maturity ...

What are the key channels by which fiscal policy affects

What are the key channels by which fiscal policy affects output in a closed versus open economy? Using the models studied in class, discuss what is meant by "crowding out", and how the crowding out effect works in an ope ...

Question what are some of the specifics of a dbms that must

Question : What are some of the specifics of a DBMS that must be taken into consideration when building a database design? The response must be typed, single spaced, must be in times new roman font (size 12) and must fol ...

Question software introduce ability do you have a document

Question : Software introduce ability do you have a document management system to manage business processes. What is the purpose of a document management system?

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As