Hello, I'm trying to write a program that evaluates a postfix expression using the vector class. I have done this successfully using stacks but I am experiencing trouble with vectors.
Here is the error message I am recieving:
I:\vector.java:26: type Vector does not take parameters
public static int evalPostfix(String str, Vector<Object> opndVect)
^
I:\vector.java:79: type Vector does not take parameters
Vector<Object> myvect = new Vector<Object>();
^
I:\vector.java:79: type Vector does not take parameters
Vector<Object> myvect = new Vector<Object>();
^
3 errors
Process completed.
Here is my code:
import java.util.*;
public class vector
{
public static int convert(char chValue)
{
switch(chValue)
{
case '0': return 0;
case '1': return 1;
case '2': return 2;
case '3': return 3;
case '4': return 4;
case '5': return 5;
case '6': return 6;
case '7': return 7;
case '8': return 8;
case '9': return 9;
default:
{
System.out.println("Error in evaluation");
return -1;
}//terminates default
}//terminates switch
}//terminates text of convert method
//begin coding for evalPostfix method
public static int evalPostfix(String str, Vector<Object> opndVect)
{
for(int index=0; index<str.length(); ++index)
{
//if current char is an integer
char chValue=str.charAt(index);
if('0'<=chValue && chValue<='9')
//add the converted integer digit to the operand vector
opndVect.add(convert(chValue));
else
{
int opnd1=opndVect.get(opndVect.lastElement());
opndVect.remove(opndVect.lastElement());
int opnd2=opndVect.get(opndVect.lastElement());
opndVect.remove(opndVect.lastElement());
switch(chValue)
{
case '+':
{
int value=opnd1+opnd2;
opndVect.add(value);
break;
}//end case +
case '*':
{
int value=opnd1*opnd2;
opndVect.add(value);
break;
}//end case *
case '-':
{
int value=opnd1-opnd2;
opndVect.add(value);
break;
}//end case -
case '/':
{
int value=opnd1/opnd2;
opndVect.add(value);
break;
}//end case /
}//terminates switch
}//terminates else
System.out.println("Top of vector is now: " + opndVect.get(opndVect.lastElement()));
}//terminates for loop
System.out.println("Evaluation: " + opndVect.get(opndVect.lastElement()));
int result=opndVect.get(opndVect.lastElement());
opndVect.remove(opndVect.lastElement());
return result;
}//terminates evalPostfix method
//begin coding of main method
public static void main(String[]args)
{
Vector<Object> myvect = new Vector<Object>();
System.out.println("Enter a string in postfix notation");
Scanner scan = new Scanner(System.in);
String str="";
str=scan.next();
evalPostfix(str, myvect);
}//terminates text of main method
}//terminates text of vector class
When I remnove the <Object> parameters from the constructor call I recieve this message:
I:\vector.java:26: type Vector does not take parameters
public static int evalPostfix(String str, Vector<Object> opndVect)
^
I:\vector.java:79: Vector is abstract; cannot be instantiated
Vector myvect = new Vector();
^
2 errors
Process completed.
Thanks in advance for any help.