Changes being made to an object in Java
<p>I have created a Compound class that holds the number of Carbon, Hydrogen, Oxygen, Nitrogen and it's bond count. I have a stack that holds these objects. </p>

<p>Initially the stack will start off at empty and I will pop that. Then I will apply addHydrogen function to it so it's Hydrogen will = 1, Oxygen=0, Nitrogen=0 and Carbon=0. </p>

<p>I then want to take the same object and apply the addCarbon function so that Hydogren will = 0, Oxygen=0, Nitrogren=0 and Carbon=1. </p>

<p>How can I write my program so I can use the same object but not with the changes I made from adding the Hydrogen? I know I could use some if cases initially but I don't think it will work because I will eventually start with a compound that has hydrogen=2, oxygen=2, Nitrogren=0, Carbon=1.</p>

<p>*I didn't include my constructors in the code, they just initialize everything to 0.  </p>

<pre><code>class compound {

    int Hydrogen;
    int Carbon;
    int Nitrogen;
    int Oxygen;
    int bond;

    public void addHydrogen(compound comp) {
        Hydrogen++;
    }

    public void addCarbon(compound comp) {
        Carbon++;
    }

}
    public static void main(String[] args) {
        Compound a= new Compound();
        a.addHydrogen(a);
        a.addCarbon(a);
    }
</code></pre>
