Eric Sage
Eric Sage

Reputation: 69

Concatenate integers in calculator app in java

So I am working with a calculator application in java, and I need to write the heart of the code.

I am writing a class that implements an interface, and in my addDigit(int digit) method I need it to display the concatenation of the two integers that the user presses on the program.

I have done some research and am finding things like value = "" + digit * digit; or something along these lines, but nothing seems to be working.

public class BasicAccumulator implements Accumulator {

    private int digit;
    private int value;

    public void BasicAccumulator(int digit, int value)
    {
        this.digit = digit;
        this.value = value;
    }

    public void addDigit(int digit)
    {
        value = digit + "" digit;
    }

    public void plus()
    {
        value = digit + digit;
    }

    public void minus()
    {
        value = digit - digit;
    }

    public void clear()
    {
        value = 0;
    }

    public int displayValue()
    {
        return value;
    }
}

Upvotes: 1

Views: 1123

Answers (2)

user1655481
user1655481

Reputation: 376

public void addDigit(int digit)
{
    value = (this.digit + "")+ digit;
}

Upvotes: 0

Keppil
Keppil

Reputation: 46209

How about:

public void addDigit(int digit)
{
    value = value * 10 + digit;
}

or am I misunderstanding what you are trying to do?

Upvotes: 4

Related Questions