Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using JAVA: Given the Code for the Interface & the Custom ArrayList; write junit test cases for testing all the functionality. ------- Interface code: public

Using JAVA: Given the Code for the Interface & the Custom ArrayList; write junit test cases for testing all the functionality.

-------

Interface code:

public interface Interface { boolean add (T item); boolean add (int index, T item) throws IndexOutOfBoundsException; int getSize(); T get(int index) throws IndexOutOfBoundsException; T remove(int index) throws IndexOutOfBoundsException; }

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Custom ArrayList

import java.util.*; public class CustomArrayList implements Interface { ArrayList arrayList = new ArrayList(); public boolean add(String item) { arrayList.add(item); return true; } public boolean add(int index, String item) { arrayList.add(index, item); return true; } public int getSize() { int size = arrayList.size(); return size; } public String get(int index) { String value = (arrayList.get(index)).toString(); return value; } public String remove(int index) { String removeitem = (arrayList.remove(index)).toString(); return removeitem; } public void printArray() { for (String element: arrayList) { System.out.println(element); } } public static void main(String args[]) { CustomArrayList object = new CustomArrayList(); System.out.println("the value added : " + object.add("a")); System.out.println("the value added : " + object.add("b")); System.out.println("the value added : " + object.add("c")); System.out.println("the value added : " + object.add(2, "d")); System.out.println(" --------Printing the Array--------"); object.printArray(); System.out.println(" Array Size: " + object.getSize()); System.out.println("Getting the Value at Index1 : " + object.get(1)); System.out.println("Removing the Value at Index1: " + object.remove(1)); System.out.println(" --------Printing the Array--------"); object.printArray(); System.out.println(" Array Size: " + object.getSize()); 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases Theory And Applications 27th Australasian Database Conference Adc 20 Sydney Nsw September 28 29 20 Proceedings Lncs 9877

Authors: Muhammad Aamir Cheema ,Wenjie Zhang ,Lijun Chang

1st Edition

3319469215, 978-3319469218

More Books

Students also viewed these Databases questions