Click here to Skip to main content
15,897,187 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I did this java progam its in OOP format.

C#
public class CO2Footprint
{
       CO2Footprint()
    {
    }




      public static  void calculateGasEmissions(int [] gas){
        double[] gasFootprint = new double[5];
        for(int counter = 0; counter <= 5; counter++){
            gasFootprint[counter] = 19.3565 * gas[counter];
                }
        }
      public double getGasEmission(double gasFootprint, int [] gasFootprints)
      {

      for(int counter = 0; counter < 5; counter++)
      {
      return gasFootprints[counter];
      }
      return gasFootprint;
      }



      public void 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;
                }
            }


    public void calcWasteReduction(int [] lightsTotal){
        double[] emissionReductions = new double[5];
        for(int counter = 0; counter <=5; counter++){
            emissionReductions[counter] = lightsTotal[counter] * 1.37 * 73;
        }
}



      public void calcGrossWasteEmission(int [] numberOfPeople) {
            double[] grossWasteEmission = new double[5];
           for(int counter = 0; counter <=5; counter++){
                grossWasteEmission[counter] = numberOfPeople[counter] * 1018;
    }

}


    public void calcNetWasteReduction(boolean [] cans,boolean [] plastic,boolean [] glass,boolean [] paper, double[] grossWasteEmission,int [] numberOfPeople, int[] emissionReductions) {

           for (int counter = 0; counter<=5; counter++){
               if (cans[counter]){
               double canReductions = 165.8;
              grossWasteEmission[counter] -= (canReductions * numberOfPeople[counter]) - emissionReductions[counter];
                   }
                }


           for (int counter = 0; counter<=5; counter++){
           if(glass[counter]){
               double glassReductions = 46.6 ;
               grossWasteEmission[counter] -= (glassReductions * numberOfPeople[counter]) - emissionReductions[counter];
                }
            }

             for (int counter = 0; counter<=5; counter++){
              if(plastic[counter]){
               double plasticReductions = 25.6;
              grossWasteEmission[counter] -= (plasticReductions * numberOfPeople[counter]) - emissionReductions[counter];
               }
            }

            for (int counter = 0; counter<=5; counter++){
             if(paper[counter]){
               double paperReductions = 184.0;
               grossWasteEmission[counter] -= (paperReductions * numberOfPeople[counter]) - emissionReductions[counter];
                }
           }





        }

}



the tester:

C#
public class CO2FootPrintTester
{
        public static void main(String[] args){



        //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=new int[5];
          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;
       }

      double[] gasFootprint = new double[5];
      double[] electricityEmissions = new double[5];
      double[] emissionReductions = new double[5];
      double[] grossWasteEmission = new double[5];


        //call methods
        for (int counter = 0; counter <=4; counter ++){

        gasFootprint[counter] = CO2Footprint.calculateGasEmissions(gas);
        electricityEmissions[counter] = CO2Footprint.calculateElectricityEmissions(avgElecBill, avgElecPrice);
        emissionReductions[counter] =  CO2Footprint.calcNetWasteReduction(cans,plastic,glass,paper, grossWasteEmission,numberOfPeople);
        grossWasteEmission[counter] = 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 am getting problems on these 4 line:
C#
gasFootprint[counter] = CO2Footprint.calculateGasEmissions(gas);
        electricityEmissions[counter] = CO2Footprint.calculateElectricityEmissions(avgElecBill, avgElecPrice);
        emissionReductions[counter] =  CO2Footprint.calcNetWasteReduction(cans,plastic,glass,paper, grossWasteEmission,numberOfPeople);
        grossWasteEmission[counter] = CO2Footprint.calcGrossWasteEmission(numberOfPeople);



Could you please see why its giving errors. It says like found void need double and stuff like that.
Posted
Comments
Sergey Alexandrovich Kryukov 16-Jan-13 15:36pm    
Problems? what problems? This is not a question, so far...
—SA
joshrduncan2012 16-Jan-13 15:38pm    
Can you present the error messages word-for-word to us so we can better understand what's going on? We can't decipher something on paraphrased wording.
Saad Abdullah 16-Jan-13 15:44pm    
the compiler says these for the 4 lines that have problems

Line1:Required double found void Line2:Required int[],int[] found double[],double[] Line3:Required boolean[],boolean[],boolean[],boolean[],double[],int[],int[] found boolean[],boolean[],boolean[],boolean[],double[],int[] Line4:required double found void

1 solution

The reason for this error is all the method you are using has return type void. you should use the proper return type.
for eg:
Java
public static  void calculateGasEmissions(int [] gas){
     double[] gasFootprint = new double[5];
     for(int counter = 0; counter <= 5; counter++){
         gasFootprint[counter] = 19.3565 * gas[counter];
             }
     }

should be like this
C#
public static  double[] calculateGasEmissions(int [] gas)
{
     double[] gasFootprint = new double[5];
     for(int counter = 0; counter <= 5; counter++){
         gasFootprint[counter] = 19.3565 * gas[counter];
             }
  return gasFootprint;
}

Change the same issue for other methods too.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900