• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Parsing a regular expression

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Write a program in Java that can parse a mathematical expression
String, calculate the expression, and produce a numeric result.

For example, given the string: "2.5+3*4+6/12-7" produce the result 8.0

Requirements: Parser
* expression can contain Integers or floating-point numbers
* expression can contain Operators for addition, subtraction, division
and multiplication
* parser should throw an Exception when the expression is invalid

Requirements: Solution
* Implement the solution in Java
* Compile and test the solution
* The solution should demonstrate good modularity, be self-contained,
reusable and extensible.
* The solution should be clearly written, easy to read, documented, and
production-quality.

Requirements: quality
* This is a timed exercise and should be completed quickly, however you
should take sufficient time to produce a quality result
* A quality solution is simple, concise, complete, well documented,
readable, adaptable, reusable, testable and robust.
 
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you tried it?
 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What does this have to do with regular expressions?
 
Ranch Hand
Posts: 262
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This exact message was also posted over at the JDC Forums (or SDN Forums - whatever they're calling it now), also by a brand new user. Nobody there can figure out what the OP wants either.
 
author
Posts: 288
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If I could understand it correctly, the String

"2.5+3*4+6/12-7"

should be parsed into individual operands and operator.

float operand1 = 2.5
char operator1 = '+'
int operand2 = 3;
char operator2 ='*'

and so on. You need to the execute the above expression which gives you the result of 8.


2.5 + (3*4) + (6/12) - 7 = 8
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think it's clear what the poster wants: someone else to do his homework for him. I guess it hasn't occurred to him that the problem is more involved than something that can be provided in a short message. Or that this isn't a place where people do other people's homework.
 
reply
    Bookmark Topic Watch Topic
  • New Topic