Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Problem with a calculator app I'm designing for class. Only diplays a zero regardless of button pressed

  1. #1
    Junior Member
    Join Date
    Mar 2019
    Posts
    2
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Problem with a calculator app I'm designing for class. Only diplays a zero regardless of button pressed

    public void buttonClick(View v){



    String id = (v.getResources().getResourceName(v.getId())).spli t("/")[1];
    switch(id){
    case "Plus":

    num1 = Double.parseDouble(Display.getText().toString());
    operator = Plus.getText().charAt(0);
    Display.setText(null);
    break;


    case "Minus":
    num1 = Double.parseDouble(Display.getText().toString());
    operator = Minus.getText().charAt(0);
    Display.setText(null);
    break;

    case "Mult":
    num1 = Double.parseDouble(Display.getText().toString());
    operator = mult.getText().charAt(0);
    Display.setText(null);
    break;

    case "Division":
    num1 = Double.parseDouble(Display.getText().toString());
    operator = division.getText().charAt(0);
    Display.setText(null);
    break;

    case "Sqrt":
    num1 = Double.valueOf(Display.getText().toString());


    break;
    case "Percent":
    num1 = Double.valueOf(Display.getText().toString());

    case "Equals":
    num2 = Double.parseDouble(Display.getText().toString());
    if(operator == '+'){
    total = num1+ num2;
    total = Double.parseDouble(Display.getText().toString());


    }else if(operator == '-'){
    total = num1-num2;
    total = Double.parseDouble(Display.getText().toString());

    }else if(operator == '\u00D7'){
    total = num1*num2;
    total = Double.parseDouble(Display.getText().toString());

    }else if(operator == '\u00f7'){
    total=num1/num2;
    total = Double.parseDouble(Display.getText().toString());


    }else if(operator == '%'){
    totaldouble)num1)*100;

    }else
    total=Math.sqrt(num1);
    total=Double.parseDouble(Display.getText().toStrin g());


    break;
    case "Decimal":
    if(num1=='0') {
    Display.setText("0" + "." + "num1");
    }
    else
    Display.setText("num1"+"."+"num1");
    break;
    case "AC":
    Display.setText("0");
    break;
    default:
    if(number.equals(one)) {
    isValid = true;
    if(number.equals(firstNumber)){
    Display.setText(Display.getText().toString()+ "1");}
    else{
    Display.setText(Display.getText().toString()+"1");
    }

    }else if(number.equals(two)){
    if(number.equals(firstNumber)){
    Display.setText(Display.getText().toString()+ "2");}
    else
    Display.setText(Display.getText().toString()+"2");


    }else if(number.equals(three)){
    if(number.equals(firstNumber)){
    Display.setText(Display.getText().toString()+"3"); }
    else
    Display.setText(Display.getText().toString()+"3");


    }else if(number.equals(four)){
    if(number.equals(firstNumber)){
    Display.setText(Display.getText().toString()+"4"); }
    else
    Display.setText(Display.getText().toString()+"4");


    }else if(number.equals(five)){
    if(number.equals(firstNumber)){
    Display.setText(Display.getText().toString()+"5"); }
    else
    Display.setText(Display.getText().toString()+"5");


    }else if(number.equals(six)){
    if(number.equals(firstNumber)){
    Display.setText( Display.getText().toString()+"6");}
    else
    Display.setText(Display.getText().toString()+"6");


    }else if(number.equals(seven)){
    if(number.equals(firstNumber)){
    Display.setText(Display.getText().toString()+ "7");}
    else
    Display.setText(Display.getText().toString()+"7");


    }else if(number.equals(eight)){
    if(number.equals(firstNumber)){
    Display.setText( Display.getText().toString()+"8");}
    else
    Display.setText(Display.getText().toString()+"8");


    }else if(number.equals(nine)){
    if(number.equals(firstNumber)){
    Display.setText( Display.getText().toString()+"9");}
    else
    Display.setText(Display.getText().toString()+"9");


    }else{
    if(number.equals(firstNumber)){
    Display.setText(Display.getText().toString()+"0"); }
    else
    Display.setText(Display.getText().toString()+"0");


    }

  2. #2
    Member
    Join Date
    Sep 2018
    Location
    Virginia
    Posts
    284
    My Mood
    Cool
    Thanks
    0
    Thanked 38 Times in 36 Posts

    Default Re: Problem with a calculator app I'm designing for class. Only diplays a zero regardless of button pressed

    Please place the code between code tags to preserve formatting. See BBCodes below. Also, the emoji obscures the text so please omit it. And include all your code.

    Regards,
    Jim

  3. #3
    Member John Joe's Avatar
    Join Date
    Jun 2017
    Posts
    277
    My Mood
    Amused
    Thanks
    8
    Thanked 19 Times in 19 Posts

    Default Re: Problem with a calculator app I'm designing for class. Only diplays a zero regardless of button pressed

    Please post stacktrace
    Whatever you are, be a good one

Similar Threads

  1. Problem with a calculator app I'm designing for class
    By Jbritt in forum Android Development
    Replies: 2
    Last Post: March 29th, 2019, 03:26 AM
  2. Designing an Account Class
    By m2msucks in forum What's Wrong With My Code?
    Replies: 16
    Last Post: July 27th, 2014, 06:05 PM
  3. how to check if a button has been pressed?
    By beginner123 in forum Java Theory & Questions
    Replies: 3
    Last Post: November 20th, 2012, 03:45 PM
  4. Pausing a loop until a button is pressed
    By amcqueen in forum AWT / Java Swing
    Replies: 1
    Last Post: October 5th, 2011, 01:57 AM
  5. Move button with mouse pressed
    By Stavros in forum What's Wrong With My Code?
    Replies: 0
    Last Post: May 10th, 2010, 08:45 AM