Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8076727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:19:27+00:00 2026-06-05T15:19:27+00:00

i’m now in java and eclipse, i just tried to build a simple calculator,

  • 0

i’m now in java and eclipse, i just tried to build a simple calculator, but i can’t make it to return with the result.

My plan was basicly that when the user click one of the operators, and the EditText isn’t empty, then First variable will be equal with the EditText, and the Operator variable change, and when the user hit Result button, and the First variable isn’t empty, then the the EditText will be equal with the Second variable, and the Result variable will be equal with the result basicly. I think i messed up something with the types and variables, but i can’t figure it out what exactly.

Could someone help?

Here is the java code;

public class Main extends Activity implements OnClickListener {
LinearLayout linear;

float First, Second, Operator, Result;

Button b1, b2, b3, b4, b5, b6, b7, b8, b9, b0, bResult, bTizedes, bSzorzas,  bKivonas, bOsztas, bOsszeadas;
EditText eT;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    First = 0;
    Second = 0;
    Operator = 0;
    Result = 0;

    b0 = (Button) findViewById(R.id.b0);
    b1 = (Button) findViewById(R.id.b1);
    b2 = (Button) findViewById(R.id.b2);
    b3 = (Button) findViewById(R.id.b3);
    b4 = (Button) findViewById(R.id.b4);
    b5 = (Button) findViewById(R.id.b5);
    b6 = (Button) findViewById(R.id.b6);
    b7 = (Button) findViewById(R.id.b7);
    b8 = (Button) findViewById(R.id.b8);
    b9 = (Button) findViewById(R.id.b9);
    bTizedes = (Button) findViewById(R.id.bTizedes);
    bSzorzas = (Button) findViewById(R.id.bSzorzas);
    bResult = (Button) findViewById(R.id.bEgyenlo);
    bKivonas = (Button) findViewById(R.id.bKivonas);
    bOsztas = (Button) findViewById(R.id.bOsztas);
    bOsszeadas = (Button) findViewById(R.id.bOsszeadas);
    eT = (EditText) findViewById(R.id.eT);

    b0.setOnClickListener(this);b1.setOnClickListener(this);b2.setOnClickListener(this);b3.setOnClickListener(this);
    b4.setOnClickListener(this);b5.setOnClickListener(this);b6.setOnClickListener(this);b7.setOnClickListener(this);
    b8.setOnClickListener(this);b9.setOnClickListener(this);bTizedes.setOnClickListener(this);bSzorzas.setOnClickListener(this);
    bResult.setOnClickListener(this);bKivonas.setOnClickListener(this);bOsztas.setOnClickListener(this);bOsszeadas.setOnClickListener(this);

    bSzorzas.setOnClickListener(new OnClickListener() {
    public void onClick(View view) {
            if(First == 0)
        {
            EditText eT = (EditText) findViewById(R.id.eT);
            float First = Float.valueOf(eT.getText().toString());
            Operator = 2;
            eT.setText(null);
        }
        else if(First != 0)
        {
            Operator = 2;
        };
        }
    });
    bKivonas.setOnClickListener(new OnClickListener() {
        public void onClick(View view) {
                if(First == 0)
            {
                EditText eT = (EditText) findViewById(R.id.eT);
                float First = Float.valueOf(eT.getText().toString());
                Operator = 4;
                eT.setText(null);
            }
            else if(First != 0)
            {
                Operator = 4;
            };
            }
        });
    bOsztas.setOnClickListener(new OnClickListener() {
        public void onClick(View view) {
                if(First == 0)
            {
                EditText eT = (EditText) findViewById(R.id.eT);
                float First = Float.valueOf(eT.getText().toString());
                Operator = 1;
                eT.setText(null);
            }
            else if(First != 0)
            {
                Operator = 1;
            };
            }
        });
    bOsszeadas.setOnClickListener(new OnClickListener() {
        public void onClick(View view) {
                if(First == 0)
            {
                EditText eT = (EditText) findViewById(R.id.eT);
                float First = Float.valueOf(eT.getText().toString());
                Operator = 3;
                eT.setText(null);
            }
            else if(First != 0)
            {
                Operator = 3;
            };
            }
        });
    bResult.setOnClickListener(new OnClickListener() {
        public void onClick(View view) {
                if(First != 0)
            {
                EditText eT = (EditText) findViewById(R.id.eT);
                float Second = Float.valueOf(eT.getText().toString());

                if(Operator == 1){
                    int Result = (int) (First) / (int) (Second);
                    eT.setText(Result);
                }

                else if(Operator == 2){
                    int Result = (int) (First) * (int) (Second);
                    eT.setText(Result);
                }

                else if(Operator == 3){
                    int Result = (int) (First) + (int) (Second);
                    eT.setText(Result);
                }

                else if(Operator == 4){
                    int Result = (int) (First) - (int) (Second);
                    eT.setText(Result);
                }

                eT.setText(null);
            }
            else if(First == 0)
            {

            };
            }
        });

}
    public void onClick(View v) {

        switch(v.getId()){

        case R.id.b0:
            eT.setText( eT.getText() + "0");
            break;
        case R.id.b1:
            eT.setText( eT.getText() + "1");
            break;
        case R.id.b2:
            eT.setText( eT.getText() + "2");
            break;
        case R.id.b3:
            eT.setText( eT.getText() + "3");
            break;
        case R.id.b4:
            eT.setText( eT.getText() + "4");
            break;
        case R.id.b5:
            eT.setText( eT.getText() + "5");
            break;
        case R.id.b6:
            eT.setText( eT.getText() + "6");
            break;
        case R.id.b7:
            eT.setText( eT.getText() + "7");
            break;
        case R.id.b8:
            eT.setText( eT.getText() + "8");
            break;
        case R.id.b9:
            eT.setText( eT.getText() + "9");
            break;
    } 
    }}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T15:19:28+00:00Added an answer on June 5, 2026 at 3:19 pm

    Try to focus on this Tutorial and see how things are done, Also try to improve it

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
Seemingly simple, but I cannot find anything relevant on the web. What is the
I want to count how many characters a certain string has in PHP, but
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.