(Simple) Add different types to ArrayList <class>

Jerome

So I need to get the int and the boolean into the contractor so I can calculate different things through methods. Is there a way I could do this through an ArrayList, or two. I just need help getting it there! Thank you for any help.

Main Method:

import java.util.ArrayList;
public class Tester
{
public static void main(String[] args)
{
   ArrayList<Contructor> cO2 = new ArrayList<Constructor>();
       // add households to the arraylist
       CO2FromWaste homeData = new CO2FromWaste();
       cO2.add();

   for(Contructor dataRecord : cO2)
   {
       dataRecord.calcGrossWasteEmission();
       dataRecord.calcWasteReduction();
       dataRecord.calcNetWasteReduction();
   }

Constructor:

public class Contructor
{
private int myNumPeople;
private boolean myPaper, myPlastic, myGlass, myCans;
private double myEmissions, myReduction, myNetEmissions;

/**
* Constructor for objects of type CO2FromWaste
* @param numPeople number of people in a household
* @param paper whether or not paper is recycled
* @param plastic whether or not plastic is recycled
* @param glass whether or not glass is recycled
* @param cans whether or not cans are recycled
*/
Contructor(int numPeople, boolean paper, boolean plastic, boolean glass, boolean cans)
{
   myNumPeople = numPeople;
   myPaper = paper;
   myPlastic = plastic;
   myGlass = glass;
   myCans = cans;
   myEmissions = 0.0;
   myReduction = 0.0;
   myNetEmissions = 0.0;
 }
Hugo Sousa

You were almost there. The ArrayList#add method takes an Object as parameter. In this case, your Object is a CO2FromWaste.

ArrayList<CO2FromWaste> cO2 = new ArrayList<CO2FromWaste>();
CO2FromWaste homeData = new CO2FromWaste();
cO2.add(homeData);

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Add different size arrays to ArrayList Java

From Dev

ArrayList<T> with different types for T

From Dev

Can I create an ArrayList of different types in Java

From Dev

copy contents of static arraylist from different class?

From Dev

ArrayList class .add error

From Dev

Putting enum types in different class

From Dev

ArrayList with different types of objects

From Dev

Add and remove class different elements

From Dev

Java class, Arraylist with multiple types

From Dev

How to add different types of delegates in QTreeView

From Dev

Javascript simple add class remove class

From Dev

JFileChooser Add different file types in filter

From Dev

How can I add the last 3 elements of an Arraylist to a different Arraylist?

From Dev

MethodError when trying to add numbers of different types

From Dev

Filenames not being added to ArrayList from different class

From Dev

ArrayList<T> with different types for T

From Dev

Can I create an ArrayList of different types in Java

From Dev

Accessing Arraylist contents from a different class?

From Dev

Why return types were different in ArrayList add methods?

From Dev

access to ArrayList from a different class

From Dev

NullPointerException in a simple ArrayList.add function?

From Dev

Putting enum types in different class

From Dev

Add extended class to ArrayList

From Dev

JFileChooser Add different file types in filter

From Dev

Find the length of an arraylist when the arraylist is located in a different Class

From Dev

How to add different types of values into arraylist<object>?

From Dev

storing custom object with different primitive types in ArrayList

From Dev

Add values to ArrayList from different activity

From Dev

Register same class for different types

Related Related

  1. 1

    Add different size arrays to ArrayList Java

  2. 2

    ArrayList<T> with different types for T

  3. 3

    Can I create an ArrayList of different types in Java

  4. 4

    copy contents of static arraylist from different class?

  5. 5

    ArrayList class .add error

  6. 6

    Putting enum types in different class

  7. 7

    ArrayList with different types of objects

  8. 8

    Add and remove class different elements

  9. 9

    Java class, Arraylist with multiple types

  10. 10

    How to add different types of delegates in QTreeView

  11. 11

    Javascript simple add class remove class

  12. 12

    JFileChooser Add different file types in filter

  13. 13

    How can I add the last 3 elements of an Arraylist to a different Arraylist?

  14. 14

    MethodError when trying to add numbers of different types

  15. 15

    Filenames not being added to ArrayList from different class

  16. 16

    ArrayList<T> with different types for T

  17. 17

    Can I create an ArrayList of different types in Java

  18. 18

    Accessing Arraylist contents from a different class?

  19. 19

    Why return types were different in ArrayList add methods?

  20. 20

    access to ArrayList from a different class

  21. 21

    NullPointerException in a simple ArrayList.add function?

  22. 22

    Putting enum types in different class

  23. 23

    Add extended class to ArrayList

  24. 24

    JFileChooser Add different file types in filter

  25. 25

    Find the length of an arraylist when the arraylist is located in a different Class

  26. 26

    How to add different types of values into arraylist<object>?

  27. 27

    storing custom object with different primitive types in ArrayList

  28. 28

    Add values to ArrayList from different activity

  29. 29

    Register same class for different types

HotTag

Archive