Hello everyone! I am quite new to java so I'm sorry in advance if my code in horrible. However, I am trying to write a program that will calculate the amount of CO2 released into the environment based on a couple of things: if you recycle, how many people are in the household, etc. My code is pretty much finished, however the output isn't working correctly. Here is the code for the "main" class with the main method inside of it:
I don't believe there is anything wrong with this portion of the code, I think it lies in the second portion:Code:public static void main(String[] args) //beginning of the main method
{
ArrayList<CO2FromWaste> CO2 = new ArrayList<CO2FromWaste>(); //declares a new ArrayList that uses objects
//add a whole bunch of different objects and values to our variables over in the other class
CO2.add(new CO2FromWaste(1, true, true, true, true));
CO2.add(new CO2FromWaste(2, false, false, false, false));
CO2.add(new CO2FromWaste(3, true, true, false, false));
CO2.add(new CO2FromWaste(4, false, false, true, true));
CO2.add(new CO2FromWaste(5, true, false, true, false));
CO2.add(new CO2FromWaste(6, false, true, false, true));
CO2FromWaste dataRecord; //declare the data record
//print the beginning of the output
System.out.printf("%15s%50s%n", "Household Waste Recycled", "Pounds of CO2");
System.out.printf("%5s%10s%10s%10s%10s%10s%20s%20s%20s%n", "Index", "People", "Paper", "Plastic", "Glass", "Cans", "Total Emission", "Reduction", "Net Emission");
System.out.println("_______________________________________________________________________________________________________________________________________");
for(int i = 0; i < CO2.size(); i++) //make a for loop that will loop for the total size of our CO2 ArrayList
{
//use the data record to call on the methods and then print the rest of the output
dataRecord = CO2.get(i);
dataRecord.calcGrossWasteEmission();
dataRecord.calcWasteReduction();
dataRecord.calcNetWasteReduction();
System.out.printf("%5d %9d %9s %9s %9s %9s %19.2f %19.2f %19.2f %n", i, dataRecord.getNumPeople(), dataRecord.isPaper(), dataRecord.isPlastic(), dataRecord.isGlass(), dataRecord.isCans(), dataRecord.getGrossWaste(), dataRecord.getGrossReduction(), dataRecord.getGrossNet());
This is just the portion of the code I am having issues with, the rest consist of getter and setter methods, which I don't think are contributing to the problem. Whenever I run the program the output says that the boolean methods from the constructor are all false, thus making the public void calcWasteReduction() method do nothing. I think the issue lies in that method, as the variables it uses are private, thus allowing it no access. Can anyone help me?Code://declare our private variables
private int numPeople;
private boolean paper, plastic, glass, cans;
private double grossWaste, grossReduction, grossNet;
/**
* This constructor receives the input for the private variables declares above in its parameters. It
* then assigns the values that were in the parameters to the private variables.
*/
CO2FromWaste(int numPPL, boolean paper, boolean plastic, boolean glass, boolean cans)
{
setNumPeople(numPPL);
paper = paper;
plastic = plastic;
glass = glass;
cans = cans;
}
/**
* This method is void (returns nothing) and receives nothing in its parameters.
* This method simply calculates the gross waste and assigns it to the corresponding variable
* at the beginning of our class
*/
public void calcGrossWasteEmission()
{
setGrossWaste(getNumPeople() * 1018);
}
/**
* This method is also void (returns nothing) and receives nothing in its parameters as well.
* This method finds out through if statements, if the household described recycles any of the following.
* If they do, then the program subtracts that amount from the total CO2 output.
*/
public void calcWasteReduction()
{
if (isPaper() == true)
setGrossReduction(getGrossReduction() + (184 * getNumPeople()));
if (isPlastic() == true)
setGrossReduction(getGrossReduction() + (25.6 * getNumPeople()));
if (isGlass() == true)
setGrossReduction(getGrossReduction() + (46.6 * getNumPeople()));
if (isCans() == true)
setGrossReduction(getGrossReduction() + (165.8 * getNumPeople()));
}
/**
* This method is also void (returns nothing) and receives nothing in its parameters as well.
* This method calculates the gross Net CO2 output by subtracting the total CO2 saved from recycling (method above)
* from the total CO2 output which are based on the amount of people in a household.
*/
public void calcNetWasteReduction()
{
setGrossNet(getGrossWaste() - getGrossReduction());
}
Thanks!

