Computer Science
Would you like to react to this message? Create an account in a few clicks or log in to continue.
Search
 
 

Display results as :
 


Rechercher Advanced Search

Keywords

Latest topics
» (2011Q2) ??????? ?????? ?41? ???????????!/????????????!?(TX 1280x720 X264 AAC).mp4
Console Calc EmptySat Feb 15, 2014 10:12 am by doriperni

» Sync2 V2.20.1312 X86x64.rar.rar
Console Calc EmptyFri Feb 14, 2014 7:37 pm by carmibire

» 9.1 Inheritance Hierarchies
Console Calc EmptyTue Feb 26, 2013 12:50 pm by ThienDinh

» Useful website
Console Calc EmptySat Dec 08, 2012 6:52 pm by tpham1991

» The Machine that Changed the World: Giant Brains. 1992 Documentary
Console Calc EmptySat Dec 08, 2012 2:16 am by ThienDinh

» Problems in practice test.
Console Calc EmptyThu Dec 06, 2012 2:32 pm by ThienDinh

» Newton's Method
Console Calc EmptyMon Dec 03, 2012 8:32 pm by ThienDinh

» Console Calc
Console Calc EmptySun Dec 02, 2012 5:57 pm by Petahwil

» Law Of Cosines
Console Calc EmptySat Dec 01, 2012 4:54 pm by Petahwil

April 2024
SunMonTueWedThuFriSat
 123456
78910111213
14151617181920
21222324252627
282930    

Calendar Calendar


Console Calc

2 posters

Go down

Whats Your Favorite Team?

Console Calc Vote_lcap25%Console Calc Vote_rcap 25% 
[ 1 ]
Console Calc Vote_lcap25%Console Calc Vote_rcap 25% 
[ 1 ]
Console Calc Vote_lcap25%Console Calc Vote_rcap 25% 
[ 1 ]
Console Calc Vote_lcap25%Console Calc Vote_rcap 25% 
[ 1 ]
 
Total Votes : 4
 
 

Console Calc Empty Console Calc

Post by Petahwil Fri Nov 30, 2012 7:18 pm

We Are Trying To Make This Into A Complex Calculator Application Post Your Ideas & Ways To Improve It!!
Remember To Vote!! Basketball ^^^^^ XD!!
Code:

import java.util.Scanner;

/**
 *
 * @author Petahwil
 */
public class ConsoleCalc {

    /**
    * @param args the command line arguments
    */
    public static void main(String[] args) {
        // TODO code application logic here
        System.out.println("Petahwil");
        Scanner in = new Scanner (System.in);
        System.out.print("Enter a Expression: ");
        String expression = in.next();
        String save = expression;
        String num1 = "";
        String num2= "";
        String operator = "";
        int result = 0;
        boolean done = false;
        boolean error = false;
        for(int i = 0; i < expression.length(); i++)
        {
            if(expression.charAt(i) >= '0' && expression.charAt(i) <= '9')
            {
                if (done == false)
                {
                    num1 = num1 +""+ expression.charAt(i);
                }
                else
                {
                    num2 = num2 +""+ expression.charAt(i);
                }
            }
            else
            {
                if (expression.charAt(i) == '+' || expression.charAt(i) == '-'
                        || expression.charAt(i) == '*'
                        ||expression.charAt(i) == '/')
                {
                    done = true;
                    operator = "" + expression.charAt(i);
                }
                else
                {
                    error = true;
                    System.out.print("Wrong Format"); break;
                }
            }
        }
        if (error == false)
        {
        if (operator.equals("+"))
        {
            result = Integer.valueOf(num1) + Integer.valueOf(num2);
        }
        else if (operator.equals("-"))
        {
            result = Integer.valueOf(num1) - Integer.valueOf(num2);
        }
        else if (operator.equals("*"))
        {
            result = Integer.valueOf(num1) * Integer.valueOf(num2);
        }
        else if (operator.equals("/"))
        {
            result = Integer.valueOf(num1) / Integer.valueOf(num2);
        }
        save += " = "+result;
        System.out.print(save);
        }
    }
}


Last edited by ThienDinh on Sun Dec 02, 2012 5:59 pm; edited 2 times in total (Reason for editing : Put code in [code] tag)

Petahwil

Posts : 8
Join date : 2012-11-30
Age : 31

Back to top Go down

Console Calc Empty Re: Console Calc

Post by ThienDinh Fri Nov 30, 2012 7:28 pm

LOL what are those teams?!?!

ThienDinh
Admin

Posts : 27
Join date : 2012-11-30

https://computerscienceqc.board-directory.net

Back to top Go down

Console Calc Empty Console Calc

Post by Petahwil Fri Nov 30, 2012 7:31 pm

Basketball teams haha!! Thats why there is a Basketball guy haha!! It said to write Break after it and it is showing it now so idk what it is doing that lol and wont let me re-edit it!

Petahwil

Posts : 8
Join date : 2012-11-30
Age : 31

Back to top Go down

Console Calc Empty Re: Console Calc

Post by ThienDinh Fri Nov 30, 2012 7:35 pm

Suspect You should be able to edit ur message. I checked the permission and it allows member to edit their own messages.

ThienDinh
Admin

Posts : 27
Join date : 2012-11-30

https://computerscienceqc.board-directory.net

Back to top Go down

Console Calc Empty Console Calc

Post by Petahwil Fri Nov 30, 2012 7:49 pm

It Lets me Just not the pole is showed up the first time but now it doesn't its not big deal just know that the break is irrelevant lol

Petahwil

Posts : 8
Join date : 2012-11-30
Age : 31

Back to top Go down

Console Calc Empty Re: Console Calc

Post by ThienDinh Fri Nov 30, 2012 7:54 pm

Ah, I get your point!

ThienDinh
Admin

Posts : 27
Join date : 2012-11-30

https://computerscienceqc.board-directory.net

Back to top Go down

Console Calc Empty Re: Console Calc

Post by Petahwil Sun Dec 02, 2012 5:57 pm

Boom! monkey
Code:

import java.util.Scanner;

/**
 *
 * @author Petahwil
 */
public class ConsoleCalc {

    /**
    * @param args the command line arguments
    */
    public static void main(String[] args) {
        // TODO code application logic here
        System.out.println("Petahwil");
        Scanner in = new Scanner(System.in);
        System.out.print("Enter a Expression: ");
        String expression = in.next();
        String save = expression;
        String num1 = "";
        String num2 = "";
        String operator = "";
        int result = 0;
        boolean done = false;
        boolean error = false;
        for (int i = 0; i < expression.length(); i++) {
            if (expression.charAt(i) >= '0' && expression.charAt(i) <= '9') {
                if (done == false) {
                    num1 = num1 + "" + expression.charAt(i);
                } else {
                    num2 = num2 + "" + expression.charAt(i);
                }
            } else {
                if (expression.charAt(i) == '+' || expression.charAt(i) == '-'
                        || expression.charAt(i) == '*'
                        || expression.charAt(i) == '/') {
                    done = true;
                    operator = "" + expression.charAt(i);
                } else {
                    error = true;
                    System.out.print("Wrong Format");
                    break;
                }
            }
        }
        if (error == false) {
            if (operator.equals("+")) {
                result = Integer.valueOf(num1) + Integer.valueOf(num2);
            } else if (operator.equals("-")) {
                result = Integer.valueOf(num1) - Integer.valueOf(num2);
            } else if (operator.equals("*")) {
                result = Integer.valueOf(num1) * Integer.valueOf(num2);
            } else if (operator.equals("/")) {
                result = Integer.valueOf(num1) / Integer.valueOf(num2);
            }
            save += "=" + result;
            System.out.print(save);


        }
          expression = in.next();
        while (expression.equals("q") == false) {
            operator = "" + expression.charAt(0);
            num1 = "";
            for (int i = 1; i < expression.length(); i++) {
                num1 += "" + expression.charAt(i);
            }
            if (operator.equals("+")) {
                result += Integer.valueOf(num1);
            } else if (operator.equals("-")) {
                result -= Integer.valueOf(num1);
            } else if (operator.equals("*")) {
                result *= Integer.valueOf(num1);
            } else if (operator.equals("/")) {
                result /= Integer.valueOf(num1);
            }
            save += expression + "=" + result;
            System.out.print(save);
            expression = in.next();
        }
    }
}

Petahwil

Posts : 8
Join date : 2012-11-30
Age : 31

Back to top Go down

Console Calc Empty Re: Console Calc

Post by Sponsored content


Sponsored content


Back to top Go down

Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum