Results 1 to 13 of 13
  1. #1
    darlineth is offline Member
    Join Date
    Jun 2008
    Location
    Philippines
    Posts
    7
    Rep Power
    0

    Default any can help me? About MDAS and PEMDAS rules.

    i have a code but this is GUI form but, i don't apply a formula of MDAS and PEMDAS and Infix-PostFix, Infix-Prefix.. it because i don't know how do these Calculator project. I'm a beginners in Java Program.

    this is the code of my Calculator.

    Java Code:
    import java.util.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    
    
    public class Calculator extends JFrame {
    	
    	private JLabel statusLabel;
    	private JTextField inputField;
    	private JButton calculate, clear, cancel, infix, prefix, postfix;
    
    	
    
    	
    	
    	
    	public Calculator()
    	
    	{
    		
    		super("Calculator in Preliminary depends using a MDAS and PEMDAS rules and Infix-postfix,  Infix-prefix rules.");
    		
    		
    		Container container= getContentPane();
    		container.setLayout(new FlowLayout());
    		
    		
    		statusLabel = new JLabel();
    	
    		
    		container.add(new JLabel("Expression: "));
    		inputField = new JTextField (20);
    		container.add(inputField);
    		
            container.add(new JLabel("Result: "));
    		inputField = new JTextField (10);
    		container.add(inputField);
    				
    		
    		// button for  Expression
    
    
    		calculate = new JButton();	
    		JButton calculate = new JButton("Calculate");
    		container.add(calculate);
    		
    		
    		
    		
    		
    		clear = new JButton();
    		JButton clear = new JButton("Clear");	
    		container.add(clear);
    		
    		cancel = new JButton();
    		JButton cancel = new JButton("Cancel");	
    		container.add(cancel);	
    			
    		infix = new JButton();
    		JButton infix = new JButton("Infix");	
    		container.add(infix);	
    			
    		prefix = new JButton();
    		JButton prefix = new JButton("Prefix");	
    		container.add(prefix);	
    			
    		postfix = new JButton();
    		JButton postfix = new JButton("Postfix");	
    		container.add(postfix);	
    			
          
    
    
    
    			
    			
    			container.add( statusLabel );
    			
    			setSize( 500, 150 );
    			setVisible( true );
    			
    			}
    	
    	public static void main (String args[])
    	
    	{
    		
    		Calculator application = new Calculator();
    		application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    	}
    	
    			
    	
    	}

  2. #2
    fishtoprecords's Avatar
    fishtoprecords is offline Senior Member
    Join Date
    Jun 2008
    Posts
    571
    Rep Power
    7

    Default

    Is there some reason you posted the same question three times?
    You should delete two of them

  3. #3
    Jeremy is offline Member
    Join Date
    Jul 2008
    Posts
    28
    Rep Power
    0

    Default

    We don't know how to do your project either. What is your question?

  4. #4
    darlineth is offline Member
    Join Date
    Jun 2008
    Location
    Philippines
    Posts
    7
    Rep Power
    0

    Default

    my question is, how can I make a formula or declaration for my Calculator project., I'm a Beginners for Java Programming. The Code that I can Post in these thread, its a GUI using JFrame... please help me,?

  5. #5
    fishtoprecords's Avatar
    fishtoprecords is offline Senior Member
    Join Date
    Jun 2008
    Posts
    571
    Rep Power
    7

    Default

    Quote Originally Posted by darlineth View Post
    my question is, how can I make a formula or declaration for my Calculator project., I'm a Beginners for Java Programming. The Code that I can Post in these thread, its a GUI using JFrame... please help me,?
    If you can't delete the redundant posts, then I'm not willing to help.

    Help is in addition to what you do yourself. So far, you'd shown us nothing.

  6. #6
    darlineth is offline Member
    Join Date
    Jun 2008
    Location
    Philippines
    Posts
    7
    Rep Power
    0

    Default

    sorry for my redundant post in this thread, but i don't know how to delete the thread. please can you delete for me. i don't know how can i delete.. thanks

  7. #7
    Jeremy is offline Member
    Join Date
    Jul 2008
    Posts
    28
    Rep Power
    0

    Default

    Are you asking us to write the logic for your calculator?

  8. #8
    darlineth is offline Member
    Join Date
    Jun 2008
    Location
    Philippines
    Posts
    7
    Rep Power
    0

    Default

    yes, I'm asking for the logic of Calculator.

  9. #9
    Jeremy is offline Member
    Join Date
    Jul 2008
    Posts
    28
    Rep Power
    0

    Default

    Well, isn't that half of your project? Do some research.

  10. #10
    darlineth is offline Member
    Join Date
    Jun 2008
    Location
    Philippines
    Posts
    7
    Rep Power
    0

    Smile Convert C# to Java

    Java Code:
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Collections;
    
    namespace pemdas
    {
        class Program
        {
            static void Main(string[] args)
            {
                string exp = "";
                Console.WriteLine("Sample Input: z / ( a + ( b - c ) * ( d - e ) ^ u ) ^ x");
                Console.Write("Enter expression: ");
                exp = Console.ReadLine();
    
                //exp = "z / ( a + ( b - c ) * ( d - e ) ^ u ) ^ x";
    
                Console.WriteLine(exp);
    
                exp = exp.Replace(" ", ",");
    
                Console.WriteLine("PostFix: " + Parse(exp));
                Console.ReadLine();
            }
            public static string Parse(string exp)
            {
                int start = exp.LastIndexOf("(");
                int end = 0;
                if (start >= 0)
                {
                    end = exp.IndexOf(")", start);
                    string subexp = exp.Substring(start, end - start + 1);
                    exp = exp.Replace(subexp, Parse(subexp.Substring(2, subexp.Length - 4)));
                    if(exp.IndexOf("(") >= 0)
                        exp = Parse(exp);
                }
                string[] items = exp.Split(',');
                ArrayList aNum = new ArrayList();
                ArrayList aOp = new ArrayList();
                string operators = "^*/+-";
                for (int x = 0; x < items.Length; x++)
                {
                    if (operators.IndexOf(items[x]) >= 0)
                    {
                        aOp.Add(items[x]);
                    }
                    else
                    {
                        aNum.Add(items[x]);
                    }
                }
    
                return ToPostFix(aNum,aOp);
            }
    
            public static string ToPostFix(ArrayList num, ArrayList op)
            {
                string[] ops = new string[] { "^", "*", "/", "+", "-" };
                for (int x = 0; x < ops.Length; x++)
                {
                    int i = op.IndexOf(ops[x]);
                    if (i >= 0)
                    {
                        int j = i + 1;
                        num[i] = num[i].ToString() + " " + num[j].ToString() + " " + op[i].ToString();
                        num.RemoveAt(j);
                        op.RemoveAt(i);
                    }
                }
                return num[0].ToString();
            }
        }
    }
    I'm Back again this Thread to ask a question.


    Hey Guys, My Calculator was solve. But i have the problem of this,


    Do you see the code on the top, that's a C#, my problem how can I convert of that code's in to Java.

    My Calculator Expression is running for MDAS rules but My Instructor said o me. That my program is need to calculate the PEMDAS rule's. I'v research for the solution of my problem, But the problem is C#. I dont how to conver this into Java.

    SOME BODY CAN HELP ME TO CONVERT THIS
    Last edited by darlineth; 09-04-2008 at 03:52 PM.

  11. #11
    serjant's Avatar
    serjant is offline Senior Member
    Join Date
    Jun 2008
    Location
    Ukraine,Zaporozhye
    Posts
    487
    Rep Power
    7

    Default

    Did you try alone to convert,show us the code what did you do for converting?

  12. #12
    darlineth is offline Member
    Join Date
    Jun 2008
    Location
    Philippines
    Posts
    7
    Rep Power
    0

    Default Convert C# to Java-

    Quote Originally Posted by serjant View Post
    Did you try alone to convert,show us the code what did you do for converting?
    Yes I'll try my best bro! but i can't understand it because of the Class String are not allow. Many Error can I Encounter, that's Why I'm Here in this Forum. To Say. help me.

  13. #13
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,266
    Rep Power
    25

    Default

    You've posted the C# code but not what you've done to convert it to java.
    One simple thing that needs to be done is to change the spelling for the classes and methods. Remember Java is case sensitive.
    For example string should be String and IndexOf should be indexOf.

Similar Threads

  1. Adding new rules in PMD eclipse plugin
    By karuna in forum Eclipse
    Replies: 1
    Last Post: 09-28-2008, 03:29 PM
  2. Forum Rules: Marking your Thread as Solved
    By DonCash in forum Forum Guides
    Replies: 0
    Last Post: 04-01-2008, 12:13 PM
  3. Architecture Rules 2.0.1
    By JavaBean in forum Java Software
    Replies: 0
    Last Post: 11-17-2007, 02:03 PM
  4. Architecture Rules 2.0-rc2
    By JavaBean in forum Java Software
    Replies: 0
    Last Post: 11-14-2007, 06:27 PM
  5. Updated Forum Rules
    By levent in forum Suggestions & Feedback
    Replies: 1
    Last Post: 08-12-2007, 01:09 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •