|
|
Welcome to the Java Forums.
You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:
- have access to post topics
- communicate privately with other members (PM)
- not see advertisements between posts
- have the possibility to earn one of our surprises if you are an active member
- access many other special features that will be introduced later.
Registration is fast, simple and absolutely free so please, join our community today!
If you have any problems with the registration process or your account login, please contact us.
|
|

07-03-2008, 01:54 PM
|
|
Member
|
|
Join Date: Jun 2008
Location: Philippines
Posts: 7
|
|
|
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.
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-04-2008, 12:40 AM
|
 |
Senior Member
|
|
Join Date: Jun 2008
Posts: 257
|
|
|
Is there some reason you posted the same question three times?
You should delete two of them
|
|

07-04-2008, 02:23 AM
|
|
Member
|
|
Join Date: Jul 2008
Posts: 26
|
|
|
We don't know how to do your project either. What is your question?
|
|

07-04-2008, 07:07 AM
|
|
Member
|
|
Join Date: Jun 2008
Location: Philippines
Posts: 7
|
|
|
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, 07:23 AM
|
 |
Senior Member
|
|
Join Date: Jun 2008
Posts: 257
|
|
Originally Posted by darlineth
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.
|
|

07-04-2008, 01:41 PM
|
|
Member
|
|
Join Date: Jun 2008
Location: Philippines
Posts: 7
|
|
|
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, 06:07 PM
|
|
Member
|
|
Join Date: Jul 2008
Posts: 26
|
|
|
Are you asking us to write the logic for your calculator?
|
|

07-05-2008, 09:10 AM
|
|
Member
|
|
Join Date: Jun 2008
Location: Philippines
Posts: 7
|
|
|
yes, I'm asking for the logic of Calculator.
|
|

07-06-2008, 12:26 AM
|
|
Member
|
|
Join Date: Jul 2008
Posts: 26
|
|
|
Well, isn't that half of your project? Do some research.
|
|

09-04-2008, 04:46 PM
|
|
Member
|
|
Join Date: Jun 2008
Location: Philippines
Posts: 7
|
|
|
Convert C# to Java
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 04:52 PM.
|
|

09-04-2008, 11:42 PM
|
 |
Member
|
|
Join Date: Jun 2008
Location: Ukraine,Zaporozhye
Posts: 53
|
|
|
Did you try alone to convert,show us the code what did you do for converting?
|
|

Today, 09:25 AM
|
|
Member
|
|
Join Date: Jun 2008
Location: Philippines
Posts: 7
|
|
|
Convert C# to Java-
Originally Posted by serjant
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.
|
|

Today, 03:21 PM
|
 |
Senior Member
|
|
Join Date: Jun 2008
Location: SW MO, USA
Posts: 972
|
|
|
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.
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|