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

  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