GetDotted Domains

Viewing Thread:
"Anyone know Java or C??"

The "Freeola Customer Forum" forum, which includes Retro Game Reviews, has been archived and is now read-only. You cannot post here or create a new thread or review on this forum.

Mon 19/11/01 at 19:36
Regular
Posts: 787
Anyone on here know JAVA and C at a fairly high level? I am learning them at Uni and was just looking for some people to talk about it and share ideas and offer and recieve help.

Anyone?
Thu 22/11/01 at 17:58
Regular
"Picking a winner!"
Posts: 8,502
Ok here is what I have started doing, just want to check Im going along the right lines, I know the code isn't complete yet, I have had loads of work lately but I'm going to try later tonight.

Thanks for actually helping, just out of interest what do you do now? What job do you have?
import java.util.*;


public class VectorStack implements Stack
{

private int i = 0;
private int size;


public VectorStack(int maxSize)
{
vect = new Vector(maxSize);
size = 0;
}

public boolean isEmpty ()
{
return(size == 0);
}

public Object getLast ()
{
if (size ==0)
throw new NoSuchElememntException();
return vect(lastElement());
}

public void clear ()
{
for(int i =0; i < size; i++)
vect(i) = null;
size = 0;
}
public void addLast (Object elem)
{

}

public Object removeLast ()
{

}


public Iterator iterator ()
{

}
}
Thu 22/11/01 at 11:47
Regular
""
Posts: 303
OK, I reckon you need to write a VectorStack class that extends from Stack, which contains an addLast method (which is what you said, isn't it?)

Stack stack = new VectorStack;
creates a new instance of VectorStack called stack

stack.addLast(new Integer(3));
calls the method addLast from stack (the new instance of VectorStack) and passes in a new integer.

'Implements the stack class' just means creates a new instance of. In this case its called VectorStack. It'll inherit the methods from stack, to which you add your own called AddLast.

Does that make sense?
Wed 21/11/01 at 20:34
Regular
"Picking a winner!"
Posts: 8,502
it is version 1.3 im using

Ok we get given a driver program, here it is

Stack stack = new VectorStack();

try
{
// stack.getLast(); // Should cause an exception when comment removed.
stack.addLast(new Integer(3));
stack.addLast(new Integer(5));
stack.addLast(new Integer(7));
System.out.print("State of stack: ");
Iterator it = stack.iterator();
while (it.hasNext())
System.out.print(" "+it.next());
System.out.println();
System.out.println(stack.removeLast());
System.out.println(stack.getLast());
System.out.println(stack.removeLast());
}
catch(NoSuchElementException e)
{
System.out.println(e.toString());
}
}
}

and we have to write the vectorstack class which implements the stack class, I think that means I have to write the methods it uses but I'm not exactly sure how you do this when it says implements stack.
Wed 21/11/01 at 13:53
Regular
""
Posts: 303
Which version of the API are you using? I've got v1.2.2 in front of me, but if you're using v1.3 it might be slightly different. I can't see an AddLast method in Vectors.

Aren't stacks last in, first out tho? ie The top of the stack is the last one put on.

Yep, Stack also inherits methods from Iterator...

What do you want VectorStack to do?
Wed 21/11/01 at 13:20
Regular
"Picking a winner!"
Posts: 8,502
I have got the API, what I have to do is this

"You must implement the given Stack interface using the the java class java.util.Vector as the basis of the implementation. The implementation should be called
VectorStack.java

Notice that the Stack interface includes an additional method iterator(), specified as:

public Iterator iterator()
This method returns the contents of the stack as an Iterator instance (see java.util.Iterator). The stack contents will be ordered from the bottom of the stack
to the top. "


Maybe you will be able to point me in the right direction, I don't want someone to do it for me just idea on how it works. For example

In the Stack interface there is a method addLast();
Does this mean that in the VectorStack one I should have a method called addLast() but as there is no add last for Vectors in the API I should be using something like add() within the addLast() method?


Hope you understand what I mean.
Wed 21/11/01 at 09:56
Regular
""
Posts: 303
Have you got the Java API there? It's all pretty well explained in there.

Stack has got 5 of its own methods - empty(), peek(), pop(), push(Object item) & search(Object o)

plus those it inherites from Vector. All your list seems to be covered either in Stack or Vector.

What are you trying to do?
Tue 20/11/01 at 21:29
Regular
"Picking a winner!"
Posts: 8,502
Using vectors I have to implement a stack class
I need to have the following methods

isEmpty()
getLast()
Clear()
addLast()
removeLast()
and Iterator()

But using vectors I don't think you can use these methods, ie I think you have to use other methods within these ones.
Tue 20/11/01 at 21:08
Regular
""
Posts: 303
compende so far, keep going...

havent got the Java doc with me here, but which methods do you need to overload?
Tue 20/11/01 at 13:24
Regular
"Picking a winner!"
Posts: 8,502
In JAVA I have to write a program to do with stacks that uses vectors, the vector stack implements the Stack class but a few of the operations have to be changed, Im having a bit of trouble with that.
Tue 20/11/01 at 13:22
Regular
""
Posts: 303
Object Orientated Design.

Vectors? they ring vague bells from my uni days, but I haven't looked at C since then.

Freeola & GetDotted are rated 5 Stars

Check out some of our customer reviews below:

Thank you very much for your help!
Top service for free - excellent - thank you very much for your help.
Many thanks!!
Registered my website with Freeola Sites on Tuesday. Now have full and comprehensive Google coverage for my site. Great stuff!!
John Shepherd

View More Reviews

Need some help? Give us a call on 01376 55 60 60

Go to Support Centre

It appears you are using an old browser, as such, some parts of the Freeola and Getdotted site will not work as intended. Using the latest version of your browser, or another browser such as Google Chrome, Mozilla Firefox, or Opera will provide a better, safer browsing experience for you.