Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

These questions relate to next questions I'll post separately (they are confuse me) Please explain. Thank you very much. Self-Check Exercise 1. What does the

These questions relate to next questions I'll post separately (they are confuse me) Please explain. Thank you very much.

Self-Check Exercise

1. What does the following code fragment do?

ArrayList myList = new ArrayList();

myList.add(3.456);

myList.add(5.0);

double result = myList.get(0) + myList.get(1);

System.out.println("Result is " + result);

2. Trace the execution of the following:

int[] anArray = {0, 1, 2, 3, 4, 5, 6, 7};

for (int i = 3; i < anArray.length 1; i++)

anArray[i + 1] = anArray[i];

and the following:

int[] anArray = {0, 1, 2, 3, 4, 5, 6, 7};

for (int i = anArray.length 1; i > 3; i--)

anArray[i] = anArray[i 1];

What are the contents of anArray after the execution of each loop?

Programming Exercise

Try to think about how to implement KWArrayList class. Please implement the following constructor and methods:

public KWArrayList()

public boolean add(E anEntry)

public E get(int index) { public E set(int index, E newValue)

public E remove(int index)

private void reallocate()

public int size()

public int indexOf(Object item)

Study the code for ArrayList implementation (enclosed in the folder) and work on the following exercise

1. Provide a constructor for class KWArrayList that accepts an int argument that represents the initial array capacity.

Use this instead of INITIAL_CAPACITY.

2. Implement the indexOf method of the KWArrayList class.

3.Write statements to remove the middle object from a KWArrayList and place it at the end.

/** Removes middle object and re-inserts it at the end @return E object removed and re-inserted */

public E removeMiddleInsertEnd()

{

}

4. Please define a tester class to verify your code.

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_2

Step: 3

blur-text-image_3

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

Database Management With Website Development Applications

Authors: Greg Riccardi

1st Edition

0201743876, 978-0201743876

More Books

Students also viewed these Databases questions

Question

2. What is the opportunity cost of seeing a movie?

Answered: 1 week ago