Hi everybody. I am writing a program that calculates the amount of Carbon Dioxide produced in a year from waste by a few selected households and comparing how recycling can reduce the CO2 footprint. However, I believe the code is correct; I am just not getting the expected output. So, something must be hosed; however, I can't figure it out. For anybody that might know the problem, I have pasted the two classes below. Thanks
[edit]New lines to keep text within width of screen. CR[/edit]
Ok so what's happening here, just like Paul said, is that your not getting to the else statements because the original if statement is true so the else statements aren't evaluated.
So just look at this example and see if it makes sense:
This is how you have it set up.
Output = 5
But what if we just tested for conditions in reverse order
Thanks everyone for the tips. I have edited the code as I think should work. I have taken out the if/else statements and replaced with all if statements. However, something is still not right as the output is still incorrect.
I would like to make some suggestions to improve the readability of your code.
1) correct your comments. It's confusing to see comments talking about triangles and shapes in a program that has nothing to do with triangles and shapes.
2) Member variables (in fact, ALL variables) should not start with a capital letter. Traditionally, class names do. So when I see something like "Paper" in your code, I think it's a class. All your boolean variables should be declared like this:
private boolean Paper, Plastic, Glass, Cans;
3) in anticipation of your next question, your constructor could then be changed to something along these lines:
4) I would suggest you get rid of your calcGrossWasteEmission() method. It's not really a mutator, since it doesn't let anyone change the value. Also, what happens if someone creates a CO2FromWaste object, but never calls this method? I would but the code for setting the grossWasteEmission value INSIDE the constructor.
Post by:autobot
Something about .... going for a swim. With this tiny ad ...
a bit of art, as a gift, the permaculture playing cards