Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 9 of 9

Thread: Carbonfp help

  1. #1
    Member llowe29's Avatar
    Join Date
    Jul 2013
    Posts
    116
    My Mood
    Tired
    Thanks
    9
    Thanked 5 Times in 5 Posts

    Default Carbonfp help

    I dont understand why I get 0.00 for all of the new bulb column.
    Here is the calculating class.
     class CO2Footprint    
     {    
             private int numP, numL, lTotal ;  
             private double eEmissions, gas, gasFP, aveBill, avePrice, paRed, plaRed
             ,gRed, cRed, eReductions,  eRTotal, gWE, tRedPaper, 
              tRedPlastic, tRedGlass, tRedCans, CO2Footprint;
             private boolean paper, plastic, glass, cans;        
     
     
       public CO2Footprint( int numberOfPeople, int gasFootPrint, double averageElectricBill,        
       double averageElectricPrice, boolean paperRecyled, boolean plasticRecyled, boolean glassRecyled,       
       boolean cansRecyled, int numLightsRecyled)         
         {    
             numP = numberOfPeople;  
             gas = gasFootPrint;  
             aveBill = averageElectricBill;  
             avePrice = averageElectricPrice;  
             paper = paperRecyled;  
             plastic = plasticRecyled;  
             glass = glassRecyled;  
             cans = cansRecyled;  
             numL = numLightsRecyled;  
     
     
     
         }     
     
     
    public double calculateGasEmissions(){  
            gasFP = 19.3565 * gas;  
            return gasFP;  
            }  
     
          public double calculateElectricityEmissions(){  
              eEmissions = (aveBill/avePrice) * 1.37 * 12;  
              return eEmissions;  
                }  
     
     
        public double calcWasteReduction(){  
           eReductions = numL * 1.37 * 73;  
           return  eReductions;  
    }  
     
           public double calcGrossWasteEmission() {  
                gWE = numP * 1018;  
                return gWE;  
     
    }  
     
     
        public double calcCanReductions() {  
                double can = 165.8;  
                    if (cans){  
                        cRed  = (can * numP);  
                    }  
                    return cRed;  
                }  
     
        public double calcGlassReductions() {  
                double glassReduce = 46.6;  
                    if(glass){  
                        gRed = (glassReduce * numP);  
     
                }  
                return gRed;  
            }  
     
     
        public double calcPlasticReductions() {     
                 double plasticReduce = 25.6;  
                 if(plastic){  
                    plaRed = (plasticReduce * numP);  
                  }  
                return plaRed;  
            }  
     
     
     
        public double calcPaperReductions() {     
                   double paperReduce = 184.0;  
                   if(paper){  
                        paRed = (paperReduce * numP);     
                }  
                return paRed;  
            }  
     
        public double calcEmissionReductionTotals() {  
                 eRTotal = paRed + plaRed + gRed + cRed;  
                 return eRTotal;  
                }  
     
     
     
        public double calcCO2Footprint() {     
                 CO2Footprint = (gas + eEmissions + gWE) - (eRTotal + eReductions);  
                 return CO2Footprint;  
                }   
    }
    Here is the tester.
    public class CO2FootprintTester    
    {  
     
           public static void main(String[] args){  
     
     
           // Create an array of 5 families  
           CO2Footprint[] fp = new CO2Footprint[5];  
           fp[0] = new CO2Footprint(3, 2604, 227.29, .084, true, true, true, true, 9);  
           fp[1] = new CO2Footprint(6, 3029, 213.28, .081, false, true, false, true, 3);  
           fp[2] = new CO2Footprint(2, 1745, 234.78, .085, true, false, true, false, 5);  
           fp[3] = new CO2Footprint(5, 3590, 256.04, .084, false, false, false, false, 1);  
           fp[4] = new CO2Footprint(1, 1362, 221.96, .086, true, true, true, true, 8);  
     
     
           for(int counter = 0; counter < 5; counter++){  
           fp[counter].calculateGasEmissions();  
           fp[counter].calculateElectricityEmissions();  
           fp[counter].calcWasteReduction();  
           fp[counter].calcGrossWasteEmission();  
           fp[counter].calcEmissionReductionTotals();   
           fp[counter].calcCO2Footprint();  
           }  
     
     
     
     
     
            //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      |");  
     
     
     
            for (int counter = 0; counter < fp.length; counter++) {  
                System.out.printf("  %5.2f", fp[counter].calculateGasEmissions());  
                System.out.printf("        %5.2f", fp[counter].calculateElectricityEmissions());  
                System.out.printf("        %5.2f", fp[counter].calcWasteReduction());  
                System.out.printf("        %5.2f", fp[counter].calcGrossWasteEmission());  
                System.out.printf("        %5.2f", fp[counter].calcEmissionReductionTotals());  
                System.out.printf("        %5.2f", fp[counter].calcCO2Footprint());  
                System.out.print("\n");  
            }  
     
     
        }  
    }

  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Carbonfp help

    As has been suggested in the past, you need to boil your problem down to an SSCCE, not your whole program. You also really need to learn how to step through this with a debugger, or at least add some print statements, to figure out what's going on. Where exactly does the behavior of the program differ from what you expect? Once you have your problem narrowed down to that, you can create a small example around anything you don't understand.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Member llowe29's Avatar
    Join Date
    Jul 2013
    Posts
    116
    My Mood
    Tired
    Thanks
    9
    Thanked 5 Times in 5 Posts

    Default Re: Carbonfp help

    I don't know exactly and you can't deduct alot from part of a program.

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Carbonfp help

    That's why we ask for an SSCCE and not a snippet. You have a bunch of functions here, which one contains the problem? Where do you see the symptoms of the problem? Providing an SSCCE makes everything a lot easier to talk about. Why would you want to make it harder for people to help you?

    Have you stepped through this with a debugger?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    Member llowe29's Avatar
    Join Date
    Jul 2013
    Posts
    116
    My Mood
    Tired
    Thanks
    9
    Thanked 5 Times in 5 Posts

    Default Re: Carbonfp help

    I have

  6. #6
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Carbonfp help

    Quote Originally Posted by llowe29 View Post
    I have
    ...and?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  7. #7
    Member llowe29's Avatar
    Join Date
    Jul 2013
    Posts
    116
    My Mood
    Tired
    Thanks
    9
    Thanked 5 Times in 5 Posts

    Default Re: Carbonfp help

    why are you so bitter with your comments, if your trying to help, help, but you need to stop condescending people. I may even report this to mod because it's really getting annoying and you do it in all the posts you respond to.

  8. #8
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Carbonfp help

    And where did you find the 4 methods calcCanReductions(), calcGlassReductions(), calcPlasticReductions(), and calcPaperReductions() were called?

    If you had traced the code backwards from the zero-value to the method that sets the value to the calling of the method, you'd have found this error in very few steps. You didn't try very hard.

    You made this same mistake before, and one of the reasons is because the object is not completely constructed in the object's constructor but left to the calling or testing program. You say that the instructor requires it to be done that way, but I'd like to see that requirement written down. It's stupid and prone to cause errors as you've now demonstrated repeatedly. If that is your understanding, you should ask the instructor why it is required to be done that way.

  9. The Following User Says Thank You to GregBrannon For This Useful Post:

    llowe29 (August 8th, 2013)

  10. #9
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Carbonfp help

    Quote Originally Posted by llowe29 View Post
    why are you so bitter with your comments, if your trying to help, help, but you need to stop condescending people. I may even report this to mod because it's really getting annoying and you do it in all the posts you respond to.
    I am a mod. If you feel I'm being overly critical, go ahead and report it, but my guess is that most people will agree with me. You don't seem to try very hard to narrow your problem down, which makes it difficult to help you. Asking you to step through it with a debugger to narrow the problem down to an SSCCE isn't being condescending, it's asking you for the bare minimum. It's actually pretty rude of you to continually post your homework without trying anything yourself. We're doing this for free, in our spare time, and asking us to essentially do your homework for you is pretty rude, not to mention probably a violation of your school's academic honesty policy.

    Now if you want help instead of to debate a tantrum, I suggest you take Greg's advice and trace through the code (sound familiar?) to determine when the code's execution differs from your expectations. This is basic debugging, which is a skill that you need to pick up sooner rather than later. Posting another homework assignment without debugging it yourself first will not help you learn.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!