Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Issues with a test driver file

  1. #1
    Junior Member
    Join Date
    Jun 2011
    Posts
    9
    My Mood
    Nerdy
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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:

    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

     
     
    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!


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default 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:

    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:

    public IOTArrayString(String name, int size)
    	{
                super(name, size);
    	}
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member
    Join Date
    Jun 2011
    Posts
    9
    My Mood
    Nerdy
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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!

Similar Threads

  1. Link From A Driver Class To The Subclasses
    By angels in forum What's Wrong With My Code?
    Replies: 1
    Last Post: May 29th, 2011, 07:39 AM
  2. Issues with writing to text file
    By surfbumb in forum What's Wrong With My Code?
    Replies: 2
    Last Post: May 12th, 2011, 09:43 AM
  3. Static class that reads from file -> performance issues?
    By rbk in forum File I/O & Other I/O Streams
    Replies: 5
    Last Post: April 18th, 2011, 09:59 AM
  4. setting JDBC driver steps
    By planmaster in forum JDBC & Databases
    Replies: 1
    Last Post: November 6th, 2010, 02:02 PM
  5. file.txt and ReadLine issues
    By chansey123 in forum File I/O & Other I/O Streams
    Replies: 2
    Last Post: March 20th, 2010, 03:46 PM