Math Addition

Binary

Member
For pure randomness, I have created a java class in less a few minutes. Save it under Calcuator.java before compiling. I'll edit this thread to improve this code. If you have questions or comments, please feel free to post here.

Code:
public class Calculator
{
    private int a, b, c;
    public Calculator()
    {
        this(0, 0);
    }
    
    public Calculator(int a, int b)
    {
        this.a = a;
        this.b = b;
    }

    public int geta()
    {
        return a;
    }
    
    public int getb()
    {
        return b;
    }
    
    public int seta(int a)
    {
        this.a = a;
        return a;
    }
    
    public int setb(int b)
    {
        this.b = b;
        return b;
    }
    
    public int total(int a, int b)
    {
        c = a + b;
        return c;
    }
        
    
    public String toString()
    {
        String results = a + " + " + b + " = " + total(a,b);
        return results;
    }
    
    public static void main(String[] args)
    {
        Calculator calc = new Calculator(2,3);
        calc.seta(5);
        calc.setb(2);
        System.out.println(calc.toString());
    }
}
 
I so wish I could understand that!

I have tried those programming for dummies but that is still a lil to hard for me... lol I guess I'm beyond dumb....
 
I'm actually learning topics way beyond that, just recapping what I have learned at the beginning. If you learn it at home by yourself, you don't get pushed so hard such as completing hardcore assignments etc. I'll be explaining bits by bits as I go along because I can learn from what I teach.
 
Code:
//start of class
public class Calculator
{
//declaring integer vars a b and c
    private int a, b, c;
    
//some mehods that sets vars a and b to 0?
public Calculator()
    {
        this(0, 0);
    }
    //sets A to a and B to b , this is because he made them private and not public ints
    public Calculator(int a, int b)
    {
        this.a = a;
        this.b = b;
    }
//take ones fucking guess
    public int geta()
    {
        return a;
    }
    
    public int getb()
    {
        return b;
    }
    //this is proberly not needed but yeah. it sets the number entered into a
    public int seta(int a)
    {
        this.a = a;
        return a;
    }
    //same as above but to b
    public int setb(int b)
    {
        this.b = b;
        return b;
    }
    
    public int total(int a, int b)
    {
        c = a + b;
        return c;
    }
        
    //turns the numbers into strings to set result. Adds a and b.
    public String toString()
    {
        String results = a + " + " + b + " = " + total(a,b);
        return results;
    }
    
//init's the whole thing, creates a new class of the "calcualtor class, sets a to 5 and b to 2 and writes the sum of them which is 7.
    public static void main(String[] args)
    {
        Calculator calc = new Calculator(2,3);
        calc.seta(5);
        calc.setb(2);
        System.out.println(calc.toString());
    }
}

Explained..
 
Back
Top