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

  The default text-based command-driven communication

If you need to create clean Web pages, which of the following is the best choice. If you need to create a text document with some graphics and format it for printing, which of the following is the best choice. Computer directories or folders are use..

  What is a mutator method and what is an accessor method

What is a mutator method? What is an accessor method? What is an implicit parameter? How does it differ from an explicit parameter?

  What is message integrity

CSCI 360: Midterm Exam. Draw a diagram that illustrates the way a MAC interacts with a message between Alice and Bob in CBC mode

  Discuss how to install snort intrusion detection system

How to Install SNORT Intrusion detection system on a virtual machine using Mint and Configure it and create a simple rule

  What are the ergonomic guidelines

Why is it important to consider the choice of colors used in presenting information on a computer display terminal? What are the ergonomic guidelines?

  What would you do if network availability is a high priority

What are the difficulties associated with wireless network connections? Discuss your experiences with wireless access point setup and configuration.

  What is the meaning of the expression sign extension

The NO? no operation instruction) has a I6-bit format. Suppose you could make it a 32-bit instruction. How would you use the additional 16 bits to increase.

  Develop a table that relates number of people

Develop a table that relates number of people to project duration for a software project requiring 50,000 LOC and 15 person-years of effort (the productivity parameter is 5000 and B 0.37).

  Create a power point presentation about inclusion

Create a Power Point Presentation about inclusion. The audience for this presentation is teachers. The presentation could be used for a teacher in-service to help alleviate teacher concerns about including students with disabilities in the classro..

  Question 1a explain the differences between the concepts of

question 1a explain the differences between the concepts of strong ai and weak aib what capabilities would a computer

  Suppose the memory cells at addresses 20 through 28 in the

suppose the memory cells at addresses 20 through 28 in the machine contain the following bit patternsaddress contents

  Questionprepare a complete tutorial including an analogy to

questionprepare a complete tutorial including an analogy to describe the mechanics and a graphic to support your

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