Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java Main topics: Arrays ArrayLists Exercise This week we will be practicing writing a portion of a class, that emulates some of the features of

Java

Main topics:

Arrays

ArrayLists

Exercise

This week we will be practicing writing a portion of a class, that emulates some of the features of a Java ArrayList. You will be writing five of the methods from this weeks homework (Assignment 5).

Getting Started

To start this exercise, you should:

1. Open eclipse and start a new Java project named Lab05

2. Add a Class (named DynArray) to this project, and copy the contents of the DynArray.java file provided into it.

3. Add a Class (named DynArrayDriver) to this project, the contents of which you will be writting from scratch.

Requirements

DynArray.java

A very simple class which models some of the functionality of the Java ArrayList. This class is not complete and must be modified as such:

1. Write the method body for the default constructor

2. Write the method body for the method arraySize()

3. Write the method body for the method elements()

4. Write the method body for the method grow()

5. Write the method body for the method shrink()

DynArrayDriver.java

A simple driver class to test your DynArray class, you must write this class from scratch

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

This is what I have so far, all I need to be finished is the elements method

public class DynArray

{

private Double[] array;

private int physicalSize;

private int effectiveSize;

public int arraySize()

{

return physicalSize;

}

public int elements()

{

//HELP

}

public DynArray()

{

this.physicalSize = 1;

this.array = new Double[this.physicalSize];

this.effectiveSize = 0;

}

private void grow()

{

Double[] tempArray = array;

physicalSize = physicalSize*2;

this.array = new Double[physicalSize];

for (int i=0;i

{

this.array[i] = tempArray[i];

}

}

private void shrink()

{

Double[] tempArray = array;

if (effectiveSize < physicalSize/2)

{

if (physicalSize % 2 == 0)

{

physicalSize = physicalSize/2;

}

else

{

physicalSize = (physicalSize/2)+1;

}

this.array = new Double[physicalSize];

}

for (int i=0;i

{

this.array[i] = tempArray[i];

}

}

}

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

Database Administration The Complete Guide To Dba Practices And Procedures

Authors: Craig S. Mullins

2nd Edition

0321822943, 978-0321822949

More Books

Students also viewed these Databases questions