Implement a method to add elements to an arraylist

Assignment Help Computer Engineering
Reference no: EM133548003

Exercise 1: Common Features of Lists

Exercise Description: Implement an abstract class called `AbstractList` that provides a skeleton implementation for common features of lists. This abstract class should define methods such as `add`, `remove`, `get`, and `size`. Then, create a concrete class called `ArrayList` that extends `AbstractList` and implements the methods using an array-based approach.

Test Cases:

1. Test Case 1:

- Input: ArrayList<Integer> list = new ArrayList<>();

- Operations:

- list.add(5);

- list.add(10);

- list.add(15);

- Expected Output:

- list.size() returns 3

- list.get(1) returns 10

2. Test Case 2:

- Input: ArrayList<String> list = new ArrayList<>();

- Operations:

- list.add("apple");

- list.add("banana");

- list.remove("apple");

- Expected Output:

- list.size() returns 1

- list.get(0) returns "banana"

Hint: Use Java 8 features like generics and method references to implement the abstract class and the concrete `ArrayList` class.

Exercise 2: Dynamic List Using an Array

Exercise Description: Implement a class called `DynamicList` that provides a dynamic list using an array-based approach. The class should automatically resize the array when necessary, and it should include methods such as `add`, `remove`, `get`, and `size`.

Test Cases

1. Test Case 1:

- Input: DynamicList<Integer> list = new DynamicList<>();

- Operations:

- list.add(5);

- list.add(10);

- list.add(15);

- Expected Output:

- list.size() returns 3

- list.get(1) returns 10

2. Test Case 2:

- Input: DynamicList<String> list = new DynamicList<>();

- Operations:

- list.add("apple");

- list.add("banana");

- list.remove("apple");

- Expected Output:

- list.size() returns 1

- list.get(0) returns "banana"

Hint: Use the concept of dynamic array resizing to implement the `DynamicList` class.

Exercise 3

Implement a method to add elements to a Collection and use an Iterator to print them

- Test Case 1: Add 'Apple', 'Banana', 'Cherry' to the collection. Expected outcome: The elements are printed in the order they were added.

- Test Case 2: Add 'Orange', 'Pear', 'Grape' to the collection. Expected outcome: The elements are printed in the order they were added.

Hint: Use the `add()` method of the Collection interface to add elements to the collection. Use an Iterator to traverse the collection and print the elements.

Exercise 4

Implement a method to add elements to an ArrayList, remove an element, and use a for-each loop to print the remaining elements

- Test Case 1: Add 'Apple', 'Banana', 'Cherry' to the ArrayList and remove 'Banana'. Expected outcome: 'Apple' and 'Cherry' are printed.

- Test Case 2: Add 'Orange', 'Pear', 'Grape' to the ArrayList and remove 'Pear'. Expected outcome: 'Orange' and 'Grape' are printed.

Hint: Use the `add()` method of the ArrayList class to add elements to the list. Use the `remove()` method to remove an element. Use a for-each loop to traverse the list and print the elements.

Reference no: EM133548003

Questions Cloud

What was the values of the qin government : What was the values of the Qin government? What was the background of the Qin before the established control over China?
Discuss how officers are engaged in jurisdictional : Identify and describe at least two federal statutes that deal with drug trafficking and related offenses. Identify and describe at least two of Tennessee
What is awk and what is it used for : What is AWK and what is it used for? Where is the name, AWK, derived from? Is AWK capable of removing or replacing data in a file? Please provide an example
What is the hazing policy at the university of florida : Find the regulation on student affairs at the University of Florida. What is the hazing policy atthe University of Florida?
Implement a method to add elements to an arraylist : Implement an abstract class called `AbstractList` that provides a skeleton implementation for common features of lists
Describe the nypd that the commissioner edward a : Describe the nypd that the commissioner Edward A. Caban is responsible for Then provide background and history of the commissioner. Focus on a particular
Describe the operational guidelines that the sheriff office : Describe the operational guidelines that the Sheriff's Office has created to fulfill these pillars, or policies, that they are aspiring to reach.
Describe one negative and one positive aspect of the factor : Describe one negative and one positive aspect of the factor and its probable effect and two ways you can intervene to reduce or eliminate the negative aspect
What major discovery did hawthorne uncover in his research : What major discovery did Hawthorne uncover in his research? How did he come across this finding?

Reviews

Write a Review

Computer Engineering Questions & Answers

  What security mecanisms can be used to ensure accountability

Employees at a law firm stole the organization's files and deleted emails. Insiders of that firm stole sensitive files for personal gain and with a clear

  How is the pruned tree used for classification

How is the pruned tree used for classification? Examine the unpruned tree. What are the top three predictors according to this tree?

  Describe the possible advantage of sibling pools

A resource pooling architecture is based on the use of one or more resource pools in which identical IT resources are grouped and maintained by a system.

  Problem utilizing the turing machine

Develop a two-track Turing machine which compares the two binary strings and decides if they are equal. If strings are equal, machine halts in some of the fixed state; if they are not equal, the machine halts in some other fixed state. Solve the s..

  First fit algorithm for bin packing

Recall the First Fit algorithm for bin packing. Show that First Fit has an approximation ratio of at most 2. In particular, for any input instance

  Determine which attributes would benefit from primary keys

As you examine the schema, you will notice that the synthetic primary keys are not automatically incremented by the DBMS, even in MSSQL, which has this ability.

  How do determine who or what will assume liability for risk

Your CIO has asked you to conduct a risk assessment on a newly acquired division that works on product development and has their own servers.

  What are the two major uses of unconstrained array types

Differentiate between the length of an array and the size of a list. What are the two major uses of unconstrained array types?

  Determine what are best values of n for various list sizes

A phase consists of N accesses in the list, for a given parameter N. Determine what are the best values of N for various list sizes.

  Provide a write up on available routers and switches

Research and provide a write up on available routers and switches. The report should include information for at least two router and two switching devices.

  Describe the pros and cons of using a multiplicative factor

Describe BRIEFLY the Additive-increase-multiplicative-decrease strategy used by the TCP congestion control algorithm.

  Describe activities to set up emergency operation center

Briefly describe the activities that need to occur to set up the emergency operation center for your company, and where your company should locate.

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