Results 1 to 13 of 13
- 07-03-2008, 12:54 PM #1
Member
- Join Date
- Jun 2008
- Location
- Philippines
- Posts
- 7
- Rep Power
- 0
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); } }
- 07-03-2008, 11:40 PM #2
Is there some reason you posted the same question three times?
You should delete two of them
- 07-04-2008, 01:23 AM #3
Member
- Join Date
- Jul 2008
- Posts
- 28
- Rep Power
- 0
We don't know how to do your project either. What is your question?
- 07-04-2008, 06:07 AM #4
Member
- Join Date
- Jun 2008
- Location
- Philippines
- Posts
- 7
- Rep Power
- 0
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,?
- 07-04-2008, 06:23 AM #5
- 07-04-2008, 12:41 PM #6
Member
- Join Date
- Jun 2008
- Location
- Philippines
- Posts
- 7
- Rep Power
- 0
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
- 07-04-2008, 05:07 PM #7
Member
- Join Date
- Jul 2008
- Posts
- 28
- Rep Power
- 0
Are you asking us to write the logic for your calculator?
- 07-05-2008, 08:10 AM #8
Member
- Join Date
- Jun 2008
- Location
- Philippines
- Posts
- 7
- Rep Power
- 0
yes, I'm asking for the logic of Calculator.
- 07-05-2008, 11:26 PM #9
Member
- Join Date
- Jul 2008
- Posts
- 28
- Rep Power
- 0
Well, isn't that half of your project? Do some research.
- 09-04-2008, 03:46 PM #10
Member
- Join Date
- Jun 2008
- Location
- Philippines
- Posts
- 7
- Rep Power
- 0
Convert C# to Java
I'm Back again this Thread to ask a question.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(); } } }
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 THISLast edited by darlineth; 09-04-2008 at 03:52 PM.
- 09-04-2008, 10:42 PM #11
Did you try alone to convert,show us the code what did you do for converting?
- 09-07-2008, 08:25 AM #12
Member
- Join Date
- Jun 2008
- Location
- Philippines
- Posts
- 7
- Rep Power
- 0
- 09-07-2008, 02:21 PM #13
Similar Threads
-
Adding new rules in PMD eclipse plugin
By karuna in forum EclipseReplies: 1Last Post: 09-28-2008, 03:29 PM -
Forum Rules: Marking your Thread as Solved
By DonCash in forum Forum GuidesReplies: 0Last Post: 04-01-2008, 12:13 PM -
Architecture Rules 2.0.1
By JavaBean in forum Java SoftwareReplies: 0Last Post: 11-17-2007, 02:03 PM -
Architecture Rules 2.0-rc2
By JavaBean in forum Java SoftwareReplies: 0Last Post: 11-14-2007, 06:27 PM -
Updated Forum Rules
By levent in forum Suggestions & FeedbackReplies: 1Last Post: 08-12-2007, 01:09 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks