Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 25-03-2010
Member
 
Join Date: Mar 2010
Posts: 202
Design calculator with HashMap

Hello
I started in java and I developed a calculator, then I put my affairs in a stringBuffer
Code:
gender (45 * 34 + 89)
I want to send this StringBuffer implements a tree in the order of precedence of operations, then I saw the HashMap. Now, my question is that, Is it a good ideas to using the hashmap in designing calculator. Any help is appreciated. Thanks in advance.
Reply With Quote
  #2  
Old 25-03-2010
Member
 
Join Date: Dec 2009
Posts: 178
Re: Design calculator with HashMap

Hello,
I am also thinking of using the hashmap in designing something like calculator. I watched how the operations walked into a binary tree but I do not see how walking with a hashmap. Please guide me if I am wrong. Value takes a number and then successively operator
Here is an example
Code:
could(key,25)
could(key +)
could(key,44)
could(key *)
could(key,8)
but I do not know what can match the key. Any help will be great. Thanks
Reply With Quote
  #3  
Old 25-03-2010
Member
 
Join Date: Nov 2009
Posts: 446
Re: Design calculator with HashMap

Hello,
I thought for a moment that you would just take the operators as keys and ordered by increasing priority.There are several ways to proceed:
One way is to determine the algorithm used to route to the operations. It has such expression prefix or inverted post-fix. Then it will just Use (Class Stack) to stack and unstack the operands. Otherwise there is the TreeMap class that implements binary trees. An elegant way is to use a composite design pattern. I do not know if any of my proposals you agree.
Reply With Quote
  #4  
Old 25-03-2010
Member
 
Join Date: Nov 2009
Posts: 333
Re: Design calculator with HashMap

Hello,
You can try the following example
Code:
2*3+3*2
gives
    Root
     /
    +
  / \
 * *
/ \ / \
2  3  3   2
 
2*(3+3)*2
gives
    Root
     /
    *
  / \
 *      2
/ \      
2  +
   / \
  3   3
Reply With Quote
  #5  
Old 25-03-2010
Member
 
Join Date: Nov 2009
Posts: 330
Re: Design calculator with HashMap

Hello,
I agree with the above code and it is the perfect way to proceed. To calculate: each node is a leaf if it has value, otherwise it is an operator, we take the result of a recursive subtree.
- Priority and therefore found the lowest in the tree.
Therefore a binary tree structure: Either tables Object [2], a class 2 attributes, one TreeNode (even if in Swing and it has not been integrated util). Hope this will help you.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Design calculator with HashMap"
Thread Thread Starter Forum Replies Last Post
Associated values with HashMap Miles Runner Software Development 5 13-02-2010 03:50 AM
Sorting a hashmap Gunner 1 Software Development 5 10-02-2010 05:06 AM
Iteration over a hashmap New ID Software Development 5 07-02-2010 03:40 AM
Replace calculator with Command Line Calculator Eric B Windows Software 3 07-05-2009 04:32 PM
What is HashMap and Map? TAIPA Software Development 4 27-02-2009 11:16 PM


All times are GMT +5.5. The time now is 02:50 PM.