nathang1392

November 6th, 2009, 01:39 AM

im trying to work the kinks out and get some advice on how to do some things. there are clearly errors in this code, but im trying to work them out. my program is supposed take some information and use it to calculate someone's carbon footprint. here are some of the instructions:

5. The program should be written in OOP

format using a tester class.

6. For the data structure, use either an array of

objects or an ArrayList.

7. Create a minimum of five different objects.

8. Your CO2 footprint should account for the

following:

• annual estimate of gasoline used

• annual estimate of electricity used

• annual household waste produced

• annual household waste recycled

• replacement of incandescent bulbs

9. The constructor should include the following parameters:

• annual gasoline used

• average electricity bill and average electricity price

• number of people in home

• recycle paper, plastic, glass, or cans (Booleans)

• number of light bulbs replaced

alright i have gotten far, i haven't yet implemented oop design because honestly i don't know how. here is how far i am with my code. i have most of the methods for the calculations worked out.

public class CO2Footprint

{

public double[] calculateGasEmissions(int [] gas){

double[] gasFootprint = new double[5];

for(int counter = 0; counter <= 5; counter++){

gasFootprint[counter] = 19.3565 * gas[counter];

}

return gasFootprint;

}

public double[] calculateElectricityEmissions(int [] averageElectricBill, int [] averageElecPrice){

double[] electricityEmissions = new double[5];

for(int counter = 0; counter <= 5; counter++){

electricityEmissions[counter] = (averageElectricBill[counter]/averageElecPrice[counter]) * 1.37 * 12;

}

return electricityEmissions;

}

public double[] calcWasteReduction(int [] lightsTotal){

double[] emissionReductions = new double[5];

for(int counter = 0; counter <=5; counter++){

emissionReductions[counter] = lightsTotal[counter] * 1.37 * 73;

}

return emissionReductions;

}

public double[] calcGrossWasteEmission(int [] numberOfPeople) {

double[] grossWasteEmission = new double[5];

for(int counter = 0; counter <=5; counter++){

grossWasteEmission[counter] = numberOfPeople[counter] * 1018;

}

return grossWasteEmission;

}

public double[] calcCanReductions(boolean [] cans,int [] numberOfPeople) {

double [] canReductions = new double[5];

double can = 165.8;

for (int counter = 0; counter<=5; counter++){

if (cans[counter]){

canReductions [counter] = (can * numberOfPeople[counter]);

}

}

return canReductions;

}

public double[] calcGlassReductions(boolean [] glass,int [] numberOfPeople) {

double[] glassReductions = new double[5];

double glassReduce = 46.6;

for (int counter = 0; counter<=5; counter++){

if(glass[counter]){

glassReductions[counter] = (glassReduce * numberOfPeople[counter]);

}

}

return glassReductions;

}

public double[] calcPlasticReductions(boolean [] plastic,int [] numberOfPeople) {

double [] plasticReductions = new double[5];

double plasticReduce = 25.6;

for (int counter = 0; counter<=5; counter++){

if(plastic[counter]){

plasticReductions[counter] = (plasticReduce * numberOfPeople[counter]);

}

}

return plasticReductions;

}

public double[] calcPaperReductions(int [] numberOfPeople, boolean [] paper) {

double paperReduce = 184.0;

double [] paperReductions = new double[5];

for (int counter = 0; counter<=5; counter++){

if(paper[counter]){

paperReductions[counter] = (paperReduce * numberOfPeople[counter]);

}

}

return paperReductions;

}

public double[] calcEmissionReductionTotals(double [] paperReductions, double [] plasticReductions, double[] glassReductions,double [] canReductions) {

double[] emissionReductionTotal = new double[5];

for (int counter =0; counter<=5; counter++){

emissionReductionTotal[counter] = paperReductions[counter] + plasticReductions[counter] + glassReductions[counter] + canReductions[counter];

}

return emissionReductionTotal;

}

}

this is mainly the part i am having trouble getting right. its not laziness i promise its just that my instructor is bad and i have gotten as far as i actually know how.

public class CO2FootPrintTester

{

public static void main(String[] args){

CO2Footprint footprint = new CO2Footprint();

//declaration of variables

int [] numberOfPeople = new int[5];;

numberOfPeople[0] = 3;

numberOfPeople[1] = 6;

numberOfPeople[2] = 2;

numberOfPeople[3] = 10;

numberOfPeople[4] = 1;

double [] avgElecBill = new double [5];;

avgElecBill[0] = 227.29;

avgElecBill[1] = 213.28;

avgElecBill[2] = 234.78;

avgElecBill[3] = 256.04;

avgElecBill[4] = 221.96;

for (int counter = 0; counter <=5; counter++){

int totalAverageElectricBill = 0;

totalAverageElectricBill += avgElecBill [counter];

int averageElectricBill = totalAverageElectricBill / 5;

}

boolean [] cans = new boolean[5];;

cans[0] = true;

cans[1] = false;

cans[2] = true;

cans[3] = false;

cans[4] = true;

boolean [] glass = new boolean[5];;

glass[0] = true;

glass[1] = false;

glass[2] = true;

glass[3] = false;

glass[4] = true;

boolean [] plastic = new boolean[5];;

plastic[0] = true;

plastic[1] = true;

plastic[2] = false;

plastic[3] = false;

plastic[4] = true;

boolean [] paper = new boolean[5];;

paper[0] = true;

paper[1] = false;

paper[2] = true;

paper[3] = false;

paper[4] = true;

int [] numLights = new int[5];;

numLights[0] = 9;

numLights[1] = 3;

numLights[2] = 5;

numLights[3] = 1;

numLights[4] = 8;

for (int counter = 0; counter<=5; counter++){

int [] lightsTotal;

lightsTotal[counter] += numLights[counter];

}

int [] gas = new int[5];;

gas[0] = 2604;

gas[1] = 3029;

gas[2] = 1745;

gas[3] = 3590;

gas[4] = 1362;

for (int counter = 0; counter<=5; counter++){

int gasTotal = 0;

gasTotal += gas[counter];

}

double [] avgElecPrice = new double[5];

avgElecPrice[0] = .084;

avgElecPrice[1] = .081;

avgElecPrice[2] = .085;

avgElecPrice[3] = .084;

avgElecPrice[4] = .086;

for (int counter = 0; counter <=5; counter++){

int totalAverageElectricPrice = 0;

totalAverageElectricPrice += avgElecPrice[counter];

int averageElecPrice = 0;

averageElecPrice = totalAverageElectricPrice / 5;

}

//call methods

double[] gasFootprint = new double[5];

gasFootprint = footprint.calcGlassReductions();(gas);

double[] electricityEmissions = new double[5];

electricityEmissions= CO2Footprint.calculateElectricityEmissions(average ElectricBill, averageElecPrice);

double[] emissionReductions = new double[5];

emissionReductions= CO2Footprint.calcNetWasteReduction(cans,plastic,gl ass,paper, grossWasteEmission,numberOfPeople);

double[] grossWasteEmission = new double[5];

grossWasteEmission= CO2Footprint.calcGrossWasteEmission(numberOfPeople );

//print results

System.out.println("| Pounds of CO2 | Pounds of CO2 | |");

System.out.println("| Emmited from | Reduced from | |");

System.out.println("| Gas | Electricity | Waste | Recycling | New Bulbs | CO2 Footprint |");

}

}

i just have a rough outline of the print, which is unimportant. its mostly getting this to have 5 objects, and work is my problem. any help is greatly appreciated. thanks alot ubuntu friends.

5. The program should be written in OOP

format using a tester class.

6. For the data structure, use either an array of

objects or an ArrayList.

7. Create a minimum of five different objects.

8. Your CO2 footprint should account for the

following:

• annual estimate of gasoline used

• annual estimate of electricity used

• annual household waste produced

• annual household waste recycled

• replacement of incandescent bulbs

9. The constructor should include the following parameters:

• annual gasoline used

• average electricity bill and average electricity price

• number of people in home

• recycle paper, plastic, glass, or cans (Booleans)

• number of light bulbs replaced

alright i have gotten far, i haven't yet implemented oop design because honestly i don't know how. here is how far i am with my code. i have most of the methods for the calculations worked out.

public class CO2Footprint

{

public double[] calculateGasEmissions(int [] gas){

double[] gasFootprint = new double[5];

for(int counter = 0; counter <= 5; counter++){

gasFootprint[counter] = 19.3565 * gas[counter];

}

return gasFootprint;

}

public double[] calculateElectricityEmissions(int [] averageElectricBill, int [] averageElecPrice){

double[] electricityEmissions = new double[5];

for(int counter = 0; counter <= 5; counter++){

electricityEmissions[counter] = (averageElectricBill[counter]/averageElecPrice[counter]) * 1.37 * 12;

}

return electricityEmissions;

}

public double[] calcWasteReduction(int [] lightsTotal){

double[] emissionReductions = new double[5];

for(int counter = 0; counter <=5; counter++){

emissionReductions[counter] = lightsTotal[counter] * 1.37 * 73;

}

return emissionReductions;

}

public double[] calcGrossWasteEmission(int [] numberOfPeople) {

double[] grossWasteEmission = new double[5];

for(int counter = 0; counter <=5; counter++){

grossWasteEmission[counter] = numberOfPeople[counter] * 1018;

}

return grossWasteEmission;

}

public double[] calcCanReductions(boolean [] cans,int [] numberOfPeople) {

double [] canReductions = new double[5];

double can = 165.8;

for (int counter = 0; counter<=5; counter++){

if (cans[counter]){

canReductions [counter] = (can * numberOfPeople[counter]);

}

}

return canReductions;

}

public double[] calcGlassReductions(boolean [] glass,int [] numberOfPeople) {

double[] glassReductions = new double[5];

double glassReduce = 46.6;

for (int counter = 0; counter<=5; counter++){

if(glass[counter]){

glassReductions[counter] = (glassReduce * numberOfPeople[counter]);

}

}

return glassReductions;

}

public double[] calcPlasticReductions(boolean [] plastic,int [] numberOfPeople) {

double [] plasticReductions = new double[5];

double plasticReduce = 25.6;

for (int counter = 0; counter<=5; counter++){

if(plastic[counter]){

plasticReductions[counter] = (plasticReduce * numberOfPeople[counter]);

}

}

return plasticReductions;

}

public double[] calcPaperReductions(int [] numberOfPeople, boolean [] paper) {

double paperReduce = 184.0;

double [] paperReductions = new double[5];

for (int counter = 0; counter<=5; counter++){

if(paper[counter]){

paperReductions[counter] = (paperReduce * numberOfPeople[counter]);

}

}

return paperReductions;

}

public double[] calcEmissionReductionTotals(double [] paperReductions, double [] plasticReductions, double[] glassReductions,double [] canReductions) {

double[] emissionReductionTotal = new double[5];

for (int counter =0; counter<=5; counter++){

emissionReductionTotal[counter] = paperReductions[counter] + plasticReductions[counter] + glassReductions[counter] + canReductions[counter];

}

return emissionReductionTotal;

}

}

this is mainly the part i am having trouble getting right. its not laziness i promise its just that my instructor is bad and i have gotten as far as i actually know how.

public class CO2FootPrintTester

{

public static void main(String[] args){

CO2Footprint footprint = new CO2Footprint();

//declaration of variables

int [] numberOfPeople = new int[5];;

numberOfPeople[0] = 3;

numberOfPeople[1] = 6;

numberOfPeople[2] = 2;

numberOfPeople[3] = 10;

numberOfPeople[4] = 1;

double [] avgElecBill = new double [5];;

avgElecBill[0] = 227.29;

avgElecBill[1] = 213.28;

avgElecBill[2] = 234.78;

avgElecBill[3] = 256.04;

avgElecBill[4] = 221.96;

for (int counter = 0; counter <=5; counter++){

int totalAverageElectricBill = 0;

totalAverageElectricBill += avgElecBill [counter];

int averageElectricBill = totalAverageElectricBill / 5;

}

boolean [] cans = new boolean[5];;

cans[0] = true;

cans[1] = false;

cans[2] = true;

cans[3] = false;

cans[4] = true;

boolean [] glass = new boolean[5];;

glass[0] = true;

glass[1] = false;

glass[2] = true;

glass[3] = false;

glass[4] = true;

boolean [] plastic = new boolean[5];;

plastic[0] = true;

plastic[1] = true;

plastic[2] = false;

plastic[3] = false;

plastic[4] = true;

boolean [] paper = new boolean[5];;

paper[0] = true;

paper[1] = false;

paper[2] = true;

paper[3] = false;

paper[4] = true;

int [] numLights = new int[5];;

numLights[0] = 9;

numLights[1] = 3;

numLights[2] = 5;

numLights[3] = 1;

numLights[4] = 8;

for (int counter = 0; counter<=5; counter++){

int [] lightsTotal;

lightsTotal[counter] += numLights[counter];

}

int [] gas = new int[5];;

gas[0] = 2604;

gas[1] = 3029;

gas[2] = 1745;

gas[3] = 3590;

gas[4] = 1362;

for (int counter = 0; counter<=5; counter++){

int gasTotal = 0;

gasTotal += gas[counter];

}

double [] avgElecPrice = new double[5];

avgElecPrice[0] = .084;

avgElecPrice[1] = .081;

avgElecPrice[2] = .085;

avgElecPrice[3] = .084;

avgElecPrice[4] = .086;

for (int counter = 0; counter <=5; counter++){

int totalAverageElectricPrice = 0;

totalAverageElectricPrice += avgElecPrice[counter];

int averageElecPrice = 0;

averageElecPrice = totalAverageElectricPrice / 5;

}

//call methods

double[] gasFootprint = new double[5];

gasFootprint = footprint.calcGlassReductions();(gas);

double[] electricityEmissions = new double[5];

electricityEmissions= CO2Footprint.calculateElectricityEmissions(average ElectricBill, averageElecPrice);

double[] emissionReductions = new double[5];

emissionReductions= CO2Footprint.calcNetWasteReduction(cans,plastic,gl ass,paper, grossWasteEmission,numberOfPeople);

double[] grossWasteEmission = new double[5];

grossWasteEmission= CO2Footprint.calcGrossWasteEmission(numberOfPeople );

//print results

System.out.println("| Pounds of CO2 | Pounds of CO2 | |");

System.out.println("| Emmited from | Reduced from | |");

System.out.println("| Gas | Electricity | Waste | Recycling | New Bulbs | CO2 Footprint |");

}

}

i just have a rough outline of the print, which is unimportant. its mostly getting this to have 5 objects, and work is my problem. any help is greatly appreciated. thanks alot ubuntu friends.