August 31, 2014
Hot Topics:
RSS RSS feed Download our iPhone app

User Code: W3Eval

  • January 9, 2002
  • By Nikola Stepan
  • Send Email »
  • More Articles »

W3Eval is a Java applet that evaluates mathematical expressions step by step. It uses a different approach than that of a conventional calculator, which is more natural to the way people calculate. When you calculate on a conventional calculator, each time you enter a new number you lose sight of the previous one. And if you make a mistake in the middle of a long expression, you have to start all over. In W3Eval, you can see all of what you are calculating, and expressions can easily be edited.

The W3Eval screen consists of three parts:

  • Tree
  • Expressions area
  • Result area

Tree is located on the left part of the screen and contains all operators, variables, and functions. It is used both as help and expression builder. When you double-click or press <Enter> on any of the terminal nodes, a template is pasted into the expressions area.

The expressions area is the upper text area of the screen. It can contain multiple expressions separated with an empty line.

The lower text area displays results and error messages.

Features:

  • evaluate mathematical expressions step by step
  • parse expressions
  • reduce parentheses
  • large number of built-in functions and operators
  • hex, oct, bin, and dec numbers
  • deg, rad, grad
  • works with "infinity" and "not-a-number"
  • user-defined variables
  • three kinds of parentheses
  • detail error checking and reporting
  • unlimited size of expressions
  • unlimited depth of nesting
  • expression builder
  • multiplatform
  • HTML help
  • automatic installation of JRE 1.3 Plug-in
  • only 50K in size

This code sample shows the definitions of the classes used for representing functions, operators, and variables:

   {
   public String function;
   public int number_of_arguments;

   public Function( String function, int number_of_arguments )
      {
      this.function=function;
      this.number_of_arguments=number_of_arguments;
      }

   public String toString()
      {
      return function;
      }
   }

public class Operator
   {
   public String operator;
   public byte priority;

   public Operator( String operator, byte priority )
      {
      this.operator=operator;
      this.priority=priority;
      }

   public String toString()
      {
      return operator;
      }
   }

public class Variable
   {
   public String variable;
   public double value;

   public Variable( String variable, double value )
      {
      this.variable=variable;
      this.value=value;
      }

   public String toString()
      {
      return variable;
      }
   }

Requirements:

About the Author

Nikola Stepan is a software engineer at ABIT Ltd., in Croatia, where he works on banking software design and development.

Java users are encouraged to submit samples of useful code for publication in the pages of Gamelan. Send your files and comments to editor@developer.com for consideration. Thank you.






Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Sitemap | Contact Us

Rocket Fuel