Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





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.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-03-2008, 01:54 PM
Member
 
Join Date: Jun 2008
Location: Philippines
Posts: 7
darlineth is on a distinguished road
Send a message via Skype™ to darlineth
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.

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); } }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-04-2008, 12:40 AM
fishtoprecords's Avatar
Senior Member
 
Join Date: Jun 2008
Posts: 257
fishtoprecords is on a distinguished road
Is there some reason you posted the same question three times?
You should delete two of them
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 07-04-2008, 02:23 AM
Member
 
Join Date: Jul 2008
Posts: 26
Jeremy is on a distinguished road
We don't know how to do your project either. What is your question?
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 07-04-2008, 07:07 AM
Member
 
Join Date: Jun 2008
Location: Philippines
Posts: 7
darlineth is on a distinguished road
Send a message via Skype™ to 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,?
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 07-04-2008, 07:23 AM
fishtoprecords's Avatar
Senior Member
 
Join Date: Jun 2008
Posts: 257
fishtoprecords is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 07-04-2008, 01:41 PM
Member
 
Join Date: Jun 2008
Location: Philippines
Posts: 7
darlineth is on a distinguished road
Send a message via Skype™ to darlineth
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
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 07-04-2008, 06:07 PM
Member
 
Join Date: Jul 2008
Posts: 26
Jeremy is on a distinguished road
Are you asking us to write the logic for your calculator?
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 07-05-2008, 09:10 AM
Member
 
Join Date: Jun 2008
Location: Philippines
Posts: 7
darlineth is on a distinguished road
Send a message via Skype™ to darlineth
yes, I'm asking for the logic of Calculator.
Bookmark Post in Technorati
Reply With Quote
  #9 (permalink)  
Old 07-06-2008, 12:26 AM
Member
 
Join Date: Jul 2008
Posts: 26
Jeremy is on a distinguished road
Well, isn't that half of your project? Do some research.
Bookmark Post in Technorati
Reply With Quote
  #10 (permalink)  
Old 09-04-2008, 04:46 PM
Member
 
Join Date: Jun 2008
Location: Philippines
Posts: 7
darlineth is on a distinguished road
Send a message via Skype™ to darlineth
Convert C# to 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 04:52 PM.
Bookmark Post in Technorati
Reply With Quote
  #11 (permalink)  
Old 09-04-2008, 11:42 PM
serjant's Avatar
Member
 
Join Date: Jun 2008
Location: Ukraine,Zaporozhye
Posts: 53
serjant is on a distinguished road
Send a message via ICQ to serjant Send a message via Skype™ to serjant
Did you try alone to convert,show us the code what did you do for converting?
Bookmark Post in Technorati
Reply With Quote
  #12 (permalink)  
Old Today, 09:25 AM
Member
 
Join Date: Jun 2008
Location: Philippines
Posts: 7
darlineth is on a distinguished road
Send a message via Skype™ to darlineth
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.
Bookmark Post in Technorati
Reply With Quote
  #13 (permalink)  
Old Today, 03:21 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: SW MO, USA
Posts: 972
Norm is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding new rules in PMD eclipse plugin karuna Eclipse 0 05-13-2008 12:39 PM
Forum Rules: Marking your Thread as Solved DonCash Forum Guides 0 04-01-2008 01:13 PM
Architecture Rules 2.0.1 JavaBean Java Announcements 0 11-17-2007 03:03 PM
Architecture Rules 2.0-rc2 JavaBean Java Announcements 0 11-14-2007 07:27 PM
Updated Forum Rules levent Suggestions & Feedback 1 08-12-2007 02:09 PM


All times are GMT +3. The time now is 06:18 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org