Implement the method and constructor with added requirement

Assignment Help Computer Engineering
Reference no: EM132104983

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;

}

Reference no: EM132104983

Questions Cloud

Discuss the aspects of distribution : Discuss the aspects of distribution when launching your new V Fusion - Is distribution an important element of the marketing mix? What value does
Clothing line of business : Should the store drop the clothing line of business based on the sales and cost data above.?
Give a new yes-instance of problem pihs : Can the set V of vertices be partitioned into exactly k disjoint sets V1; V2; V3.... Vk such that, for 1
Income statement for september : The company expects to sell $560 units in September. Example of an income statement for September using contribution margin format.
Implement the method and constructor with added requirement : addAll( ) : adjust the type of the parameter, it is an ArrayBag with the same generic type parameter; the method checks.
Explore the issue of truthfulness in the stable matching : Explore the issue of truthfulness in the Stable Matching Problem and specifically in the Gale-Shapley algorithm.
Determine the big-oh for the performance of your algorithm : The numbers are read by the program from a file. The numbers in the file are not necessarily sorted.
Create a struct that contains four integer fields : To do this problem, you will need to dynamically create a struct that contains 4 integer fields. The fields should be called X, Y, TheSum and TheProduct.
Show the tables in 1nf and 2nf that are created in process : Use the process of normalization to transform the table below into 3NF. Show the tables in 1NF and 2NF that are created in the process.

Reviews

Write a Review

Computer Engineering Questions & Answers

  Mathematics in computing

Binary search tree, and postorder and preorder traversal Determine the shortest path in Graph

  Ict governance

ICT is defined as the term of Information and communication technologies, it is diverse set of technical tools and resources used by the government agencies to communicate and produce, circulate, store, and manage all information.

  Implementation of memory management

Assignment covers the following eight topics and explore the implementation of memory management, processes and threads.

  Realize business and organizational data storage

Realize business and organizational data storage and fast access times are much more important than they have ever been. Compare and contrast magnetic tapes, magnetic disks, optical discs

  What is the protocol overhead

What are the advantages of using a compiled language over an interpreted one? Under what circumstances would you select to use an interpreted language?

  Implementation of memory management

Paper describes about memory management. How memory is used in executing programs and its critical support for applications.

  Define open and closed loop control systems

Define open and closed loop cotrol systems.Explain difference between time varying and time invariant control system wth suitable example.

  Prepare a proposal to deploy windows server

Prepare a proposal to deploy Windows Server onto an existing network based on the provided scenario.

  Security policy document project

Analyze security requirements and develop a security policy

  Write a procedure that produces independent stack objects

Write a procedure (make-stack) that produces independent stack objects, using a message-passing style, e.g.

  Define a suitable functional unit

Define a suitable functional unit for a comparative study between two different types of paint.

  Calculate yield to maturity and bond prices

Calculate yield to maturity (YTM) and bond prices

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd