Click here to Skip to main content
15,917,997 members
Home / Discussions / Java
   

Java

 
AnswerRe: what is the use of String tokenizer? Pin
fly90416-Mar-09 23:17
fly90416-Mar-09 23:17 
GeneralRe: what is the use of String tokenizer? Pin
akosidandan16-Mar-09 23:51
akosidandan16-Mar-09 23:51 
QuestionHTML encoding characters [modified] Pin
chris martin16-Mar-09 3:58
chris martin16-Mar-09 3:58 
Questionworking in aglets environment Pin
girusp16-Mar-09 3:48
girusp16-Mar-09 3:48 
QuestionCapture image using web camera Pin
amitjadhavaj15-Mar-09 3:40
amitjadhavaj15-Mar-09 3:40 
QuestionJava script which will remove duplicates in html page. Pin
kimjim43613-Mar-09 21:22
kimjim43613-Mar-09 21:22 
AnswerJavaScript is one word, and it is not Java. Pin
Naruki23-Mar-09 21:13
Naruki23-Mar-09 21:13 
QuestionDrained Pin
jonig1913-Mar-09 20:31
jonig1913-Mar-09 20:31 
I can't find the nullpointer error I'm having with netbeans and it's getting to me, any help would be appreciated. Below is my code of a class that will evaluate a RPN expression given in prefix form. I included one of the methods. they all look the same except either it has .minus .plus .times. The stack declared, can only hold Object types which is why the casting was neccessary. I know a little bit about Generics but I can't use them. I really, would appreciate any help. Thanks in advance hopefully.

public class PrefixEvaluator
{
   private final int MAX_SIZE = 60;
   private BufferedReader stdin;
   //private Vector<Fraction> FractionList = new Vector<Fraction>();
   private Stack evaluate = new Stack(MAX_SIZE);
   private boolean valid = true;
   private Object answer1 = new Object();
   
   void run() throws IOException
   {
      String toEval = stdin.readLine(); 

      while( toEval != null && valid )
      {
         Object op1 = new Object();
         Object op2 = new Object();
       
         int eqns = 1;    
         System.out.println( "Raw Expression " + eqns + " is: " + toEval );         
         ReverseTokenizer equation = new ReverseTokenizer( toEval, " ");
         String token = equation.nextToken();
         if( token.charAt(0) == '(')
         {
            evaluate.push( token );
         }
         else if ( token.charAt(0) == '+' || 
                   token.charAt(0) == '*' || 
                   token.charAt(0) == '-'   )
         {
            if( evaluate.isEmpty() )
               System.out.println( "Invalid Expression" );
            else
            {   
               op2 = evaluate.pop();
               op1 = evaluate.pop();
               if( token.equals("+"))
                  addition(op1, op2);
               else if( token.equals("-"))
                  subtract(op1, op2);
               else if( token.equals("*"))
                  multiply(op1, op2);
               else
                  System.out.println( "Invalid Expression" );
            }
            eqns++;
         }
        
         toEval = stdin.readLine();
      }
      answer1 = evaluate.pop();
   }

   public void addition( Object op1, Object op2)
   {
      Fraction operand1 = new Fraction();
      Fraction operand2 = new Fraction();
      Fraction addAns = new Fraction();
      Object answer = new Object();
      operand1 = (Fraction)op1;
      operand2 = (Fraction)op2;
      addAns = operand1.plus(operand2);
      answer = (Object)addAns;
      evaluate.push(answer);
   }

Answer[Message Deleted] Pin
fly90414-Mar-09 1:26
fly90414-Mar-09 1:26 
GeneralRe: Drained Pin
jonig1914-Mar-09 7:56
jonig1914-Mar-09 7:56 
GeneralRe: Drained Pin
fly90414-Mar-09 12:26
fly90414-Mar-09 12:26 
GeneralRe: Drained Pin
jonig1914-Mar-09 13:17
jonig1914-Mar-09 13:17 
QuestionCase Insensitive Array Search Pin
LordLothar13-Mar-09 19:14
LordLothar13-Mar-09 19:14 
AnswerRe: Case Insensitive Array Search Pin
fly90414-Mar-09 1:20
fly90414-Mar-09 1:20 
QuestionBluetooth Door Lock (J2ME application). Pin
legand`13-Mar-09 7:12
legand`13-Mar-09 7:12 
AnswerRe: Bluetooth Door Lock (J2ME application). Pin
hookies fawaz5-Apr-09 15:43
hookies fawaz5-Apr-09 15:43 
QuestionPadding problem occure from Unix to window using Java Base32 Pin
Murugan k12-Mar-09 2:31
Murugan k12-Mar-09 2:31 
AnswerRe: Padding problem occure from Unix to window using Java Base32 Pin
Nagy Vilmos12-Mar-09 3:02
professionalNagy Vilmos12-Mar-09 3:02 
QuestionHow to access default port Pin
Nitharshan11-Mar-09 19:02
Nitharshan11-Mar-09 19:02 
QuestionRGB Cube Pin
trucha1365711-Mar-09 7:08
trucha1365711-Mar-09 7:08 
QuestionEnd process Pin
yesu prakash10-Mar-09 2:08
yesu prakash10-Mar-09 2:08 
AnswerRe: End process Pin
Nagy Vilmos10-Mar-09 2:44
professionalNagy Vilmos10-Mar-09 2:44 
Question[Message Deleted] Pin
Darshan Fulfagar9-Mar-09 23:42
Darshan Fulfagar9-Mar-09 23:42 
AnswerRe: JTree in a JTable Pin
Nagy Vilmos9-Mar-09 23:44
professionalNagy Vilmos9-Mar-09 23:44 
Question[Message Deleted] Pin
Darshan Fulfagar9-Mar-09 23:40
Darshan Fulfagar9-Mar-09 23:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.