954,545 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

calculator

Hi there ,
I need a calculator that is flexible enough to perform
+,-,/,%,^and *.
can you help plz:?:

Embeza
Light Poster
48 posts since Jun 2006
Reputation Points: 10
Solved Threads: 0
 

If you are suppossed to be writing one, then write one, and if you have a specific problem, check back with us. If you simply want to find one to use, check with Google, there are more than enough out there.

masijade
Industrious Poster
Moderator
4,253 posts since Feb 2006
Reputation Points: 1,471
Solved Threads: 494
 
Hi there , I need a calculator that is flexible enough to perform +,-,/,%,^and *. can you help plz:?:

So basically you want a calculator in java which emulates the one in windows.

There should be lots of examples out there, even some which handles more complex crap like RPN notation. I'm feeling bored (holidays) :sad: I might write a RPN calculator with a nice gui for fun.

iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
 

tat easy.. u haf each button add a actionlistener..
and inside the action listener perform the required statements lor.
i did that in my school before

N[e]tt[e]
Newbie Poster
18 posts since Feb 2005
Reputation Points: 10
Solved Threads: 0
 

For u it might be.There is surely a difference between you and me but the aim of this forum is to exchange ideas.Not to overact and undermine others.
Any way the calculator will be using numbers as input from the buttons as well as from a text file.
That is to say the file will have random real numbers arranged randomly.You have to input thos numbers from the file.
For example if the file has "3,7.9,-9.3,100" then the user has to choose which numbers to take as operands.Its a kind of assigning the text into a string variable, splitting it into parts and manipulating with the elements of the array of the strings.

tat easy.. u haf each button add a actionlistener..
and inside the action listener perform the required statements lor.
i did that in my school before

Embeza
Light Poster
48 posts since Jun 2006
Reputation Points: 10
Solved Threads: 0
 

The idea is to help others, not to enlist them to do your homework for you.
You showed no interest at all in doing anything of your own, just sitting back and waiting for a complete solution to be handed to you on a golden platter.

That's not going to fly, especially since you're not paying us consultancy fees (at $150 an hour per person for a minimum of 80 hours per person).

jwenting
duckman
Team Colleague
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
 
iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
 

Thank you for your solutions
But I dont know java very well.
What I know is VB 6.0 and VB.NET
and also as to the content of your hard work you have developed a converter(to number from string).That is good but i need inputs to be selected randomly from the file.
The only thing I should ask everybody is how to select interest operands i.e any operands of interest from the text file.
Thank you.
Embeza

Embeza
Light Poster
48 posts since Jun 2006
Reputation Points: 10
Solved Threads: 0
 
and also as to the content of your hard work you have developed a converter(to number from string).That is good but i need inputs to be selected randomly from the file. The only thing I should ask everybody is how to select interest operands i.e any operands of interest from the text file.


Hullo, can you please explain this in greated detail with an example.

Reading from a file is simple when you know how. But what does the file input look like?

iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
 

So you helped the kid by doing his homework for him, now he can claim a decent grade for doing no work at all.
What does that do for the profession, except causing even more unqualified idiots to enter the marketplace?

jwenting
duckman
Team Colleague
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
 

Hi Jamttwee

I appreciate your ambition to help me.

What I want is that a calculator that can do calculations based on input from a specific file as well as directly from the numeric button of the interface. The former is more difficult than the latter for me.
So, I would prefer if you do on the former one.
For clarity, the file can be either a text file or a database file. In any case its format looks as below:
"0,2,3,4,5,6,7,8,9,+,-,/,^,%"
Then the system has to store this content into a string array and read from the array for calculation.
Let me knowif any ambiguity
Thanks

Embeza
Light Poster
48 posts since Jun 2006
Reputation Points: 10
Solved Threads: 0
 

Hey,
Your replies are annoying me.
Annoying people is much simpler than building them.
This is not expected from a professional.
Plz try to be friendly.
Try to help me rather.
with regards

Embeza
Light Poster
48 posts since Jun 2006
Reputation Points: 10
Solved Threads: 0
 

Hey,
Your replies are annoying me.
Annoying people is much simpler than building them.
This is not expected from a professional.
Plz try to be friendly.
Try to help me rather.
with regards:-|

Embeza
Light Poster
48 posts since Jun 2006
Reputation Points: 10
Solved Threads: 0
 

Hi Jamttwee

I appreciate your ambition to help me.

What I want is that a calculator that can do calculations based on input from a specific file as well as directly from the numeric button of the interface. The former is more difficult than the latter for me. So, I would prefer if you do on the former one. For clarity, the file can be either a text file or a database file. In any case its format looks as below: "0,2,3,4,5,6,7,8,9,+,-,/,^,%" Then the system has to store this content into a string array and read from the array for calculation. Let me knowif any ambiguity Thanks

Hullo there, I still don't understand the example you have given. Especially since your most recent example contradicts your previous one. That is to say the file will have random real numbers arranged randomly.You have to input thos numbers from the file.
For example if the file has "3,7.9,-9.3,100" then the user has to choose which numbers to take as operands.Its a kind of assigning the text into a string variable, splitting it into parts and manipulating with the elements of the array of the strings.

iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
 
Hey, Your replies are annoying me. Annoying people is much simpler than building them. This is not expected from a professional. Plz try to be friendly. Try to help me rather. with regards:-|

What's annoying is you can't do a simple calculator program and you want someone else to do it for you.

server_crash
Postaholic
2,111 posts since Jun 2004
Reputation Points: 113
Solved Threads: 20
 

It's not annoying if someone has a problem; and the question doesn't seem like a homework request either.

If you're reading exressions from a file, you need a way to parse the contents of the file and recognise operands; java DOES have a simple evaluate function, so you can do Integer.decode(String : s) : int to automatically calculate very simple things (I think, +, - and *). Unfortunately there's no similar Float.decode() or Double.decode() functions.

For more complex things, you'll have to do a String recognitition on every character that COULD be an operand, while buffering values that are numbers; as you reach "lower levels" of the calculation, calculate the results, then keep moving upwards until you get the result of the whole calculation.

Can get very complicated if you want to offer an equivilant inline calculation spec as Java, if you always have 2 operators and an operand it's far easier, if I had the String "5 + 4" I could split it by "+" then add the contents of split[0] and split[2], if it didn't split, I could then try splitting by "*" and so on.

I don't know if Java supports regular expressions in the String.split() function, that would be much helpful; although I suppose you'd never know where your operators were before the split.

Java is quite different from VB; there are methodical similarilities but the structure is far from. How would you do it in VB? the same method will probably apply to Java, if missing functions are a problem, think about what the VB functions actually do, and all of them (except Windows API depents/calls) will translate easily into Java.

Matt

MattEvans
Veteran Poster
Moderator
1,386 posts since Jul 2006
Reputation Points: 522
Solved Threads: 64
 
Hullo there, I still don't understand the example you have given. Especially since your most recent example contradicts your previous one.


I know it is contradicting that's because I have done the the way of using the buttons . But now i need inputs from files.
E.g eth.txt="0,2,4,1,7,8,9,6,+,-,/"
and you have prepared a form with controls in it then
your program will put the numbers and operators in appropriate buttons.For instance 0 will be the value to be displayed on the diplay textbox when the button with text "0" displayed on it is clicked. The operator addition will be executed if the add button is clicked. The only new thing is how to display a number n on the display box when the button representing that number is clicked- all inputs are from the text file.
thanks

Embeza
Light Poster
48 posts since Jun 2006
Reputation Points: 10
Solved Threads: 0
 

you can bring the numbers from the text file easily enough, do you know how to do java file access?

getting operators from text in actual methods is more difficult, you'll either have to pre-write possible methods in your java app and chose one based on comparison, or make your app extensible/updatable and allow your user to write classes to handle their custom operations.

Matt

MattEvans
Veteran Poster
Moderator
1,386 posts since Jul 2006
Reputation Points: 522
Solved Threads: 64
 

In that link I gave you open up the CalcGUI class.

In there find the line:-

String buttonOrder = "789456123 0 ";
E.g eth.txt="0,2,4,1,7,8,9,6,+,-,/"

Change the line to this:-

String buttonOrder = "02417896";


You'll notice the interface has changed. So effectively all you should be doing is reading your stuff from the text file and assigning that line to the variable buttonOrder ?

With the exception of the operators it should be as simple as that?

Yes? No?

iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
 
It's not annoying if someone has a problem; and the question doesn't seem like a homework request either. If you're reading exressions from a file, you need a way to parse the contents of the file and recognise operands; java DOES have a simple evaluate function, so you can do Integer.decode(String : s) : int to automatically calculate very simple things (I think, +, - and *). Unfortunately there's no similar Float.decode() or Double.decode() functions. For more complex things, you'll have to do a String recognitition on every character that COULD be an operand, while buffering values that are numbers; as you reach "lower levels" of the calculation, calculate the results, then keep moving upwards until you get the result of the whole calculation. Can get very complicated if you want to offer an equivilant inline calculation spec as Java, if you always have 2 operators and an operand it's far easier, if I had the String "5 + 4" I could split it by "+" then add the contents of split[0] and split[2], if it didn't split, I could then try splitting by "*" and so on. I don't know if Java supports regular expressions in the String.split() function, that would be much helpful; although I suppose you'd never know where your operators were before the split. Java is quite different from VB; there are methodical similarilities but the structure is far from. How would you do it in VB? the same method will probably apply to Java, if missing functions are a problem, think about what the VB functions actually do, and all of them (except Windows API depents/calls) will translate easily into Java. Matt


Oh thanks
But I would be more satisfied if you tell me some about how to code the necessary functions

Embeza
Light Poster
48 posts since Jun 2006
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You