Issues with a test driver file
So I have an assignment to make a file that tests the functionality of methods within a string queue structure. I'm sort of new to multiple classes within a program, so maybe I'm doing this wrong. What I'm trying to do right now is extend the queue class and all of the enclosed methods to a test class which will have methods with additional testing functionality (Exception throwing with feedback to the user). The problem I'm having is within the test class (which is still pretty bare bones at this point). I'm getting this error message "Implicit super constructor ArrayStringQueue() is undefined for default constructor. Must define an explicit constructor". As I understand it, I need to make new constructors for the test class itself, but when I do I get this error, "Implicit super constructor ArrayStringQueue() is undefined. Must explicitly invoke another constructor". I'm not sure what's going on
Anyways here is the StringQueue Class:
Code Java:
import java.util.*;
import java.lang.Exception;
public class ArrayStringQueue implements StringQueueInterface
{
protected int indexmarker = 0; //holds position of current front index
protected String queueName; //holds name of queue
protected String[] queue; //String array to hold user defined strings
protected int listmarker = -1; //holds position of current index in regards to add
protected String name;
protected static int numElements = 0;
public ArrayStringQueue(String name, int maxSize)
{
//Precondition: maxSize>0
//creates an empty arrayStringQueue object, applies a name, and sets a limit for the number of indices
this.name = name;
queue = new String[maxSize];
}
public ArrayStringQueue(String name)
{
//secondary constructor, creates an empty string array of size 100, with a user defined name
queue = new String[100];
this.name = name;
}
public void enqueue(String element) throws Exception
{
//precondition: queue is not full
//increases listmarker value
//adds a string to the queue
if(isFull())
throw new Exception("Queue is full.");
else
{
if (listmarker == queue.length - 1)
listmarker = 0;
else
listmarker++;
queue[listmarker] = element;
numElements++;
}
}
public String dequeue() throws Exception
{
// increase value of indexMarker if indexmarker is not at the end of the queue
//returns String at the current index of the indexMarker value
if(isEmpty())
throw new Exception("Queue is empty.");
else
{
String returnString = queue[indexmarker];
queue[indexmarker] = null;
if (indexmarker == queue.length - 1)
indexmarker = 0;
else
indexmarker++;
numElements--;
return returnString;
}
}
public boolean isFull()
{
//searches queue to see if it is full
return (numElements == queue.length);
}
public boolean isEmpty()
{
//searches queue to see if it is empty
return(numElements == 0);
}
public int getSize()
//returns size of current queue
{
return (numElements);
}
public boolean contains(String element)
{
//returns true if passed String is found within the queue, else returns false
//will ignore case sensitivity
int location = 0;
boolean found = false;
while ((location <= listmarker) && !found)
{
if (element.equalsIgnoreCase(queue[location])) // if element is the same as the index value
return true;
else
{
location++;
}
}
return found;
}
public void reset()
{
//returns queue indices to their original null value
//returns both listmarker and indexmarker to their original positions
for (int i = 0; i < queue.length; i++)
queue[i] = null;
listmarker = -1;
indexmarker = -1;
}
public String getName()
{
//returns name of queue
return name;
}
public String toString()
{
//returns a string that contains a formatted version of the contents of the queue
String queueString = ("Queue: " + name + "\n\n");
for (int i = 0; i <= listmarker; i++)
queueString = queueString + (i+1) + "." + queue[i] + "\n";
return queueString;
}
}
and the Test Driver
Code Java:
public class IOTArrayString extends ArrayStringQueue
{
public static void main(String[] args)
{
}
public IOTArrayString(String name, int size)
{
}
public boolean testEnqueue(String str1)
{
//precondition: Array cannot be full/listmarker cannot be at array.length - 1
boolean isTrue;
if (listmarker < queue.length - 1)
{
this.enqueue(str1);
isTrue = true;
}
else
isTrue = false;
return isTrue;
}
public boolean testDequeue()
{
// precondition: Array cannot be empty, listMarker cannot be < 0
boolean isTrue;
if (listmarker > 0 )
}
public boolean testIsFull()
{
//in order for this test to be true, top must be at array.length - 1
}
public boolean testReset()
{
}
public boolean testContains()
{
}
}
Don't pay attention to the // comments in either file, they are old and flawed.
Thanks for any help!
Re: Issues with a test driver file
When you're in a subclass (and you always are, everything is a subclass of Object), there is an implied call to the super-class's no-args constructor. If you wrote it out, it would just look like this:
Code java:
public IOTArrayString(String name, int size)
{
super();
}
The problem is, your superclass (ArrayStringQueue) doesn't have a no-args constructor. So you want to pass the arguments up using something like:
Code java:
public IOTArrayString(String name, int size)
{
super(name, size);
}
Re: Issues with a test driver file
Ahh, sorry for the late reply. I've been bogged down in school work.
Thanks for the reply! It solved my issue and furthered my Java knowledge!