Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I keep getting this error. Can someone please help me? ----jGRASP exec: javac -g DArray.java DArray.java:108: error: cannot find symbol buffer = DArrays.copyOf(buffer, buffer.length +

I keep getting this error. Can someone please help me?

----jGRASP exec: javac -g DArray.java DArray.java:108: error: cannot find symbol buffer = DArrays.copyOf(buffer, buffer.length + size); ^ symbol: variable DArrays location: class DArray 1 error

----jGRASP wedge2: exit code for process is 1. ----jGRASP: operation complete.

public class DArray { private final double GROW_FACTOR = 0.5;// array size growing rate private final int DEFAULT_SIZE = 10;// default array size public DArray() { this.size =10; } //attributes private int size; private int buffer[]; //the actual array //constructors /** create an array of default size */ public DArray(int size) throws Exception { if(size < 0) { throw new Exception("Not a valid range"); } this.size = size;//the actual array size int bufferSize = (int) Math.ceil(this.size + this.size * GROW_FACTOR); this.buffer = new int[bufferSize]; //create the buffer } //methods

/** * * @return the actual size of the array */ public int length() { return this.size; } /** * * @return the max length of the dynamic array */ public int maxLength() { return this.buffer.length; } /** * * @param index - the location of the element in the array * @return the element at the given location/index */ public int elementAt(int index) throws Exception { if(index < 0 || index >= this.size) if (index< 0 || index>=maxLength()) throw new Exception("Index out of bound"); return this.buffer[index]; } /** *putting a value into the array at the given index *@param value the intem to be placed into the array *@param index the index where the value to be placed *@return none */ public void set(int index, int value) { this.buffer[index]=value; if(index>maxLength()) { resize(index); set(index,value); }

else buffer[index]=value;

}

public void resize(int size) { buffer = DArrays.copyOf(buffer, buffer.length + size); }

public int getFirst() { return buffer[0]; }

public int getLast() { return buffer[maxLength()-1]; }

////////////////////////////////////////////////////////// //driver to test the code public static void main(String[] args) throws Exception { DArray a = new DArray(10); System.out.println(a.length()); System.out.println(a.maxLength()); DArray b = new DArray();//testing default size array System.out.println("Default size: "+ b.length()); a.set(0, 10); //set value 10 into index 0 a.set(100, 50);//set value 50 to index 100 System.out.println("Element at 100 position is:" +a.elementAt(100)); a.resize(2); System.out.println("New length of the array:"+a.maxLength()); System.out.println("First element is "+a.getFirst()); System.out.println("Last element is "+a.getLast()); }//end of main

}//end of DArray class

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

Big Data Fundamentals Concepts, Drivers & Techniques

Authors: Thomas Erl, Wajid Khattak, Paul Buhler

1st Edition

0134291204, 9780134291208

More Books

Students also viewed these Databases questions

Question

How do we organise for international logistics?

Answered: 1 week ago