array of objects confusion

i have started on this project that calculated the carbon foot print of a family. i have been working on it for a few days now. for the sake of not having to explain what i am trying to do i will simply post 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. well i am trying to do that. i have done every thing i know to do, and now im posting as a last resort. im not 100% sure what all my problems are. im aware that they are there though. if anyone can help me figure out what to do to make it work correctly i would greatly appreciate it.

I agree with Janeice, I would have made an abstract or concrete class that contains the getters and setters, followed by child classes that would extend from that. Then in my tester class I would create an object that simply calls those methods.

You have too many concepts going on in one class and it becomes confusing. You could do all of this with only 1 (one) for loop.

For example-

Hopefully that will help some. This is the basic concept of OO programming and is extremely powerful in helping a computer scientist in solving real world problems.

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

thank you guys for all of your valuable feedback. i just have one more thing to ask. i just got an update on the assignment from my teacher and it seems that i may have been making things harder than needed.

2. All of the arrays you have as input into the constructor CO2FootPrint should be primitives: int nbrPeople, double, avgElectBill, etc.
3. I have not gone into detail look at your methods but a cursory look seems you are in the right direction but are trying to use the array parameters. Use simple primitives.

You see, CO2FootPrint is an object that knows its elements that goes into its carbon footprint and can return any value needed concerning its footprint. You create it with its basic knowledge and then it can calculate all of its emmission and waste data for whoever is interested using the getters.

now im really confused because what i thought i had to be doing i changed. can someone give me some feed back on what changes i might need to make to get this back on track?

I think he's saying each object has primitives as its components (instance variables, and method parameters).

The array part should be an array enclosing each instance of the CO2Footprint class (what I've been calling Family this whole time).

Right now, you're calculating ALL the family's footprints at the same time (by passing an array of values to the method). You should make it so only one calculation is done at a time (by passing only one value at a time).... then if you need more you can run the method again on the next instance in the array of objects.

Work smarter not harder. Make the JVM do the work for you.

nathan gibson
Ranch Hand

Joined: Sep 16, 2009
Posts: 120

posted Nov 07, 2009 17:27:15

0

i have been working and i have used you guys advice. i have my first class compiling with no errors, but my second is still a work in progress. im getting a .class expected error on

here is my completed class

and this is the one thats giving me alot of trouble. im still pretty new to objects and im trying to get through my first actual program using them. if someone would help me troubleshoot it i would greatly appreciate it. this code can be overwhelming.

One other thing to remember.... when you make a constructor that takes parameters, if you WANT a no parameter constructor, you need to make one. The JVM only creates a no parameter constructor if you don't create ANY constructors.

A little clearer now?

nathan gibson
Ranch Hand

Joined: Sep 16, 2009
Posts: 120

posted Nov 07, 2009 23:20:23

0

i got both of my classes to compile without errors. thank you so much for the help. i wish you could feel my excitement. thankyou for the help once agian.