[advanced search]
Results from the most recent live auction are here.
13 members in the live chat room. Join Chat!
Register Rules & FAQ NP$ Store Active Threads Mark Forums Read
Go Back   NamePros.Com > Marketplace :: Design & Development > Developers For Hire
User Name
Password

Old 12-15-2006, 02:12 PM   · #1
DNhub
NamePros Regular
 
DNhub's Avatar
 
Trader Rating: (2)
Join Date: Mar 2006
Posts: 268
NP$: 34.50 (Donate)
DNhub has a spectacular aura aboutDNhub has a spectacular aura about
Help! Easy JAVA job - Quick $1.44 @ paypal instant + $10 echeck @ paypal

I need someone to finish a simple calculator code in JAVA in the next 2hours.



Basically, the input is a string with an operation on this format: "4+25+14/2*6-2+5"



Want I need it to solve this using the right order of operations:



The way it must be solve is trough extracting first 5 tokens (already done) from the string, assign them to variables, and solve according to the right order of operations, then extracting 2 more and continue solving until the string is empty and all the opperations are done. All these must be done with only 5 variables, meaning that you would need to do moving of values after each operation if necessary.



I'm looking for someone fast, I really need this in a couple of hours, As I said, about 45%+ of the code I already wrote.



Here's the code:



calculator.java

Code:
import java.util.*; public class calculator { public String operString; public float Num1; public char Oper1; public float Num2; public char Oper2; public float Num3; public String tempStr; public float tempResult; private boolean isValidd(String s) { String validChars = "+-/*0123456789."; boolean isValidd = true; for (int i = 0; i < s.length() && isValidd; i++) { char c = s.charAt(i); if (validChars.indexOf(c) == -1) { isValidd = false; } else { isValidd = true; } } return isValidd; } public void eval() { String theRegex = "\\+|-|\\*|/"; String[] split = operString.split(theRegex); // get first 3 numbers to an array Num1 = Integer.parseInt(split[0]); Num2 = Integer.parseInt(split[1]); Num3 = Integer.parseInt(split[2]); tempStr = operString; int conT = 1; for(int i=0;i<tempStr.length();i++) // get opperator 1 to variables { if (conT == 1) { char a = tempStr.charAt(i); if(a=='+' || a=='-' || a=='*' || a=='/') { Oper1 = a; conT = 0; } } } tempStr = tempStr.substring(tempStr.indexOf(Oper1)+1, tempStr.length() ); // Get new String conT = 1; for(int i=0;i<tempStr.length();i++) // get opperator 2 to variable { if (conT == 1) { char a = tempStr.charAt(i); if(a=='+' || a=='-' || a=='*' || a=='/') { Oper2 = a; conT = 0; } } } tempStr = operString.substring(operString.indexOf(split[3])-1, operString.length() ); System.out.println(tempStr); /*Continue Code here*/ public void input() { Scanner keyboard = new Scanner(System.in); System.out.println("\nPlease your operation in this format ex: 41+14*5+2/4"); operString = keyboard.nextLine(); operString = operString.replaceAll(" ", ""); //removes white spaces from string } public void output() { eval(); System.out.println(Result); } }




main.java (just to input and display results)

Code:
public class main { public static void main(String[] args) { calculator o1 = new calculator(); o1.input(); o1.output(); } }




Whoever Finish the code 1st and PM, will be the winner. As I said in the title, I will give $1.44 intanlty to the winner, and also a $10 through and echeck which usually takes 3 or 4 days to clear out.



Thanks


Please register or log-in into NamePros to hide ads
DNhub is online now   Reply With Quote
Closed Thread

NamePros is a revenue sharing forum.

Thread Tools

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
Forum Jump


Site Sponsors
Hunting Moon http://www.mobisitetrader.com/ Traffic Down Under
Advertise your business at NamePros
All times are GMT -7. The time now is 05:44 AM.


Powered by: vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0