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

  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

    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 == '%'){
    total double ) 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. The Following User Says Thank You to Jbritt For This Useful Post:


  3. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Problem with a calculator app I'm designing for class

    You forgot to describe your problem and post any output to show it.

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  4. The Following User Says Thank You to Norm For This Useful Post:


  5. #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

    Please post stacktrace
    Whatever you are, be a good one

Similar Threads

  1. Designing an Account Class
    By m2msucks in forum What's Wrong With My Code?
    Replies: 16
    Last Post: July 27th, 2014, 06:05 PM
  2. Calculator app
    By bodylojohn in forum Object Oriented Programming
    Replies: 14
    Last Post: April 7th, 2014, 06:28 AM
  3. Help designing a class hierarchy for a Java program
    By zmsras in forum What's Wrong With My Code?
    Replies: 0
    Last Post: March 21st, 2014, 03:31 AM
  4. Problem in JSP Page Designing
    By vinothkumarrvk in forum JavaServer Pages: JSP & JSTL
    Replies: 0
    Last Post: March 10th, 2010, 01:09 AM
  5. Calculator application using java
    By fabolous04 in forum Paid Java Projects
    Replies: 4
    Last Post: March 25th, 2009, 11:29 AM