Click here to Skip to main content
15,949,686 members
Home / Discussions / Java
   

Java

 
GeneralRe: Java Code using the List Interface not Compiling Pin
Afzaal Ahmad Zeeshan9-Nov-17 0:22
professionalAfzaal Ahmad Zeeshan9-Nov-17 0:22 
GeneralRe: Java Code using the List Interface not Compiling Pin
Richard MacCutchan9-Nov-17 1:12
mveRichard MacCutchan9-Nov-17 1:12 
AnswerRe: Java Code using the List Interface not Compiling Pin
Richard MacCutchan8-Nov-17 22:06
mveRichard MacCutchan8-Nov-17 22:06 
AnswerRe: Java Code using the List Interface not Compiling Pin
vishaljamdagni7-Feb-18 1:21
professionalvishaljamdagni7-Feb-18 1:21 
QuestionError Trapping this statement Pin
Member 135080347-Nov-17 2:59
Member 135080347-Nov-17 2:59 
AnswerRe: Error Trapping this statement Pin
Richard MacCutchan7-Nov-17 3:31
mveRichard MacCutchan7-Nov-17 3:31 
GeneralRe: Error Trapping this statement Pin
Member 135080347-Nov-17 5:28
Member 135080347-Nov-17 5:28 
GeneralRe: Error Trapping this statement Pin
Richard MacCutchan7-Nov-17 6:56
mveRichard MacCutchan7-Nov-17 6:56 
GeneralRe: Error Trapping this statement Pin
Member 135080347-Nov-17 7:23
Member 135080347-Nov-17 7:23 
AnswerRe: Error Trapping this statement Pin
jschell8-Nov-17 7:29
jschell8-Nov-17 7:29 
AnswerRe: Error Trapping this statement Pin
ZurdoDev8-Nov-17 7:44
professionalZurdoDev8-Nov-17 7:44 
QuestionPlacing 2DArray Values into x, y locations Pin
Member 135019553-Nov-17 7:35
Member 135019553-Nov-17 7:35 
QuestionIS anybody knows how to convert HTML to XML file USING java Pin
Raaz db Bengalore3-Nov-17 3:12
Raaz db Bengalore3-Nov-17 3:12 
AnswerRe: IS anybody knows how to convert HTML to XML file USING java Pin
jschell3-Nov-17 6:47
jschell3-Nov-17 6:47 
GeneralRe: IS anybody knows how to convert HTML to XML file USING java Pin
Raaz db Bengalore3-Nov-17 20:54
Raaz db Bengalore3-Nov-17 20:54 
GeneralRe: IS anybody knows how to convert HTML to XML file USING java Pin
Richard MacCutchan4-Nov-17 21:09
mveRichard MacCutchan4-Nov-17 21:09 
GeneralRe: IS anybody knows how to convert HTML to XML file USING java Pin
Raaz db Bengalore5-Nov-17 16:58
Raaz db Bengalore5-Nov-17 16:58 
GeneralRe: IS anybody knows how to convert HTML to XML file USING java Pin
Richard MacCutchan5-Nov-17 22:09
mveRichard MacCutchan5-Nov-17 22:09 
GeneralRe: IS anybody knows how to convert HTML to XML file USING java Pin
Raaz db Bengalore5-Nov-17 22:19
Raaz db Bengalore5-Nov-17 22:19 
QuestionHi all can anyone solve this for me plz in java Pin
Jbdomnic12321-Oct-17 4:28
Jbdomnic12321-Oct-17 4:28 
AnswerRe: Hi all can anyone solve this for me plz in java Pin
Sascha Lefèvre21-Oct-17 4:40
professionalSascha Lefèvre21-Oct-17 4:40 
AnswerRe: Hi all can anyone solve this for me plz in java Pin
jschell23-Oct-17 7:36
jschell23-Oct-17 7:36 
QuestionCalculator App for order of operations (Android Studio) Pin
Member 1347677620-Oct-17 17:40
Member 1347677620-Oct-17 17: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 21:54
mveRichard MacCutchan20-Oct-17 21:54 
AnswerRe: Calculator App for order of operations (Android Studio) Pin
jschell23-Oct-17 7:58
jschell23-Oct-17 7:58 

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.