Click here to Skip to main content
15,850,359 members
Home / Discussions / Java
   

Java

 
AnswerRe: Error Trapping this statement Pin
jschell8-Nov-17 8:29
jschell8-Nov-17 8:29 
AnswerRe: Error Trapping this statement Pin
ZurdoDev8-Nov-17 8:44
professionalZurdoDev8-Nov-17 8:44 
QuestionPlacing 2DArray Values into x, y locations Pin
Member 135019553-Nov-17 8:35
Member 135019553-Nov-17 8:35 
QuestionIS anybody knows how to convert HTML to XML file USING java Pin
Raaz db Bengalore3-Nov-17 4:12
Raaz db Bengalore3-Nov-17 4:12 
AnswerRe: IS anybody knows how to convert HTML to XML file USING java Pin
jschell3-Nov-17 7:47
jschell3-Nov-17 7:47 
GeneralRe: IS anybody knows how to convert HTML to XML file USING java Pin
Raaz db Bengalore3-Nov-17 21:54
Raaz db Bengalore3-Nov-17 21:54 
GeneralRe: IS anybody knows how to convert HTML to XML file USING java Pin
Richard MacCutchan4-Nov-17 22:09
mveRichard MacCutchan4-Nov-17 22:09 
GeneralRe: IS anybody knows how to convert HTML to XML file USING java Pin
Raaz db Bengalore5-Nov-17 17:58
Raaz db Bengalore5-Nov-17 17:58 
GeneralRe: IS anybody knows how to convert HTML to XML file USING java Pin
Richard MacCutchan5-Nov-17 23:09
mveRichard MacCutchan5-Nov-17 23:09 
GeneralRe: IS anybody knows how to convert HTML to XML file USING java Pin
Raaz db Bengalore5-Nov-17 23:19
Raaz db Bengalore5-Nov-17 23:19 
QuestionHi all can anyone solve this for me plz in java Pin
Jbdomnic12321-Oct-17 5:28
Jbdomnic12321-Oct-17 5:28 
AnswerRe: Hi all can anyone solve this for me plz in java Pin
Sascha Lefèvre21-Oct-17 5:40
professionalSascha Lefèvre21-Oct-17 5:40 
AnswerRe: Hi all can anyone solve this for me plz in java Pin
jschell23-Oct-17 8:36
jschell23-Oct-17 8:36 
QuestionCalculator App for order of operations (Android Studio) Pin
Member 1347677620-Oct-17 18:40
Member 1347677620-Oct-17 18:40 
Not sure what's going wrong with my code-any suggestions? This is a basic calculator in Android Studio. It needs to be able to do multi-number operations(using order of operations). Currently, if you enter 2+2*6, it'll only do 2*6. Also, when you hit the Clear button, the 0 from the display stays tacked on, and I'm not sure how to get rid of it.Thanks!

package com.example.10012698.calculatorproject;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.StringTokenizer;
public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    Button button0, button1, button2, button3, button4, button5, button6,
            button7, button8, button9, buttonadd, buttonsubtract, buttonmultiply,
            buttondivide, buttonequals, buttonclear;
    TextView display;
    String displaytext="";
    double result;
    double x, y;
    ArrayList<String> list;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        button0 = (Button) findViewById(R.id.button0);
        button1 = (Button) findViewById(R.id.button1);
        button2 = (Button) findViewById(R.id.button2);
        button3 = (Button) findViewById(R.id.button3);
        button4 = (Button) findViewById(R.id.button4);
        button5 = (Button) findViewById(R.id.button5);
        button6 = (Button) findViewById(R.id.button6);
        button7 = (Button) findViewById(R.id.button7);
        button8 = (Button) findViewById(R.id.button8);
        button9 = (Button) findViewById(R.id.button9);
        buttonadd = (Button) findViewById(R.id.buttonadd);
        buttonsubtract = (Button) findViewById(R.id.buttonsubtract);
        buttonmultiply = (Button) findViewById(R.id.buttonmultiply);
        buttondivide = (Button) findViewById(R.id.buttondivide);
        buttonclear = (Button) findViewById(R.id.buttonclear);
        buttonequals = (Button) findViewById(R.id.buttonequals);
        display = (TextView) findViewById(R.id.display);
        display.setOnClickListener(this);
        list = new ArrayList<>();
    }

    public void onClick(View view)
    {
        if(!(view.equals(buttonclear)&&!(view.equals(buttonequals))))
        {
           display.setText(display.getText()+""+((Button)view).getText());

        if(displaytext.equals("0"))
        {
            display.setText(" ");
        }

        if(view.equals(buttonclear))
        {
            display.setText(" ");
        }

        if(view.equals(buttonequals))
        {
            displaytext= displaytext.substring(0,displaytext.length()-1);
            StringTokenizer operators= new StringTokenizer(displaytext, "+-*/",true);

            while(operators.hasMoreTokens())
            {
                list.add(operators.nextToken());
            }

                for(int j=0; j<list.size()-1; j++)
                {
                    if (list.get(j).equals("*") || list.get(j).equals("/"))
                    {
                        x = Double.parseDouble(list.get(j - 1));
                        y = Double.parseDouble(list.get(j + 1));

                        if (list.get(j).equals("*"))
                        {
                            result+=(x*y);
                        }

                        if (list.get(j).equals("/"))
                        {
                            result+=(x/y);
                        }
                    }
                }
                for(int k=0;k<list.size()-1;k++)
                {
                    if (list.get(k).equals("+") || list.get(k).equals("-"))
                    {
                        x = Double.parseDouble(list.get(k - 1));
                        y = Double.parseDouble(list.get(k + 1));

                        if (list.get(k).equals("+"))
                        {
                            result+=(x+y);
                        }

                        if (list.get(k).equals("-"))
                        {
                            result+=(x-y);
                        }
                    }
                }
        }
        display.setText(""+result);


    }
}

AnswerRe: Calculator App for order of operations (Android Studio) Pin
Richard MacCutchan20-Oct-17 22:54
mveRichard MacCutchan20-Oct-17 22:54 
AnswerRe: Calculator App for order of operations (Android Studio) Pin
jschell23-Oct-17 8:58
jschell23-Oct-17 8:58 
QuestionTrying to develop an app at school using java-mobile app Pin
Member 1347677620-Oct-17 18:03
Member 1347677620-Oct-17 18:03 
QuestionRe: Trying to develop an app at school using java-mobile app Pin
Richard MacCutchan20-Oct-17 22:50
mveRichard MacCutchan20-Oct-17 22:50 
QuestionAnalyze the structure of a class (with package dependence) Pin
Hager.Harald14-Oct-17 13:25
professionalHager.Harald14-Oct-17 13:25 
AnswerRe: Analyze the structure of a class (with package dependence) Pin
Richard MacCutchan14-Oct-17 21:55
mveRichard MacCutchan14-Oct-17 21:55 
AnswerRe: Analyze the structure of a class (with package dependence) Pin
jschell15-Oct-17 9:07
jschell15-Oct-17 9:07 
GeneralRe: Analyze the structure of a class (with package dependence) Pin
Hager.Harald15-Oct-17 22:18
professionalHager.Harald15-Oct-17 22:18 
QuestionJava compile time Errors Pin
Pruthivi_Dev7-Oct-17 4:34
Pruthivi_Dev7-Oct-17 4:34 
AnswerRe: Java compile time Errors Pin
Richard Deeming9-Oct-17 9:33
mveRichard Deeming9-Oct-17 9:33 
AnswerRe: Java compile time Errors Pin
Manish K. Agarwal12-Oct-17 5:37
Manish K. Agarwal12-Oct-17 5:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.