public class CO2FromWasteTester
{
public static void main(String[] args){
ArrayList<C02FromWaste> C02 = new ArrayList<C02FromWaste>(5);
C02.add(new C02FootPrint(1, true, true, true, true));
C02.add(new C02FootPrint(3, true, false, true, true));
C02.add(new C02FootPrint(4, false, false, false, false));
C02.add(new C02FootPrint(1, true, true, true, true));
C02.add(new C02FootPrint(1, true, true, true, true));
}
}
Using an array list
Page 1 of 16 Replies - 727 Views - Last Post: 09 November 2009 - 12:35 PM
#1
Using an array list
Posted 09 November 2009 - 12:05 PM
im having to do a remake of a previous assignment using an array list. previously i had used an array of objects. im going from an example, but it looks like i did it right and im getting this error cannot find symbol class ArrayList
Replies To: Using an array list
#2
Re: Using an array list
Posted 09 November 2009 - 12:08 PM
Did you import java.util.*?
#3
Re: Using an array list
Posted 09 November 2009 - 12:13 PM
i made a change, i now get <identifier expected>
import java.util.*;
public class CO2FromWasteTester
{
public static void main(String[] args){
ArrayList<C02FootPrint> C02 = new ArrayList<C02FootPrint>(5);
C02.add(new (1, true, true, true, true));
C02.add(new C02FootPrint(3, true, false, true, true));
C02.add(new C02FootPrint(4, false, false, false, false));
C02.add(new C02FootPrint(1, true, true, true, true));
C02.add(new C02FootPrint(1, true, true, true, true));
}
}
#4
Re: Using an array list
Posted 09 November 2009 - 12:15 PM
I could be wrong but I think this line is your issue:
Shouldnt it be
C02.add(new (1, true, true, true, true));
Shouldnt it be
C02.add(new C02FootPrint(1, true, true, true, true));
#5
Re: Using an array list
Posted 09 November 2009 - 12:24 PM
im working the error around. i have two classes.
now it says that it cannot find my constructor CO2FromWasteTester(int,boolean,boolean,boolean,boolean)
public class CO2FromWaste
{
public int numberOfPeople;
public int numPeople;
public double grossWasteEmission;
public boolean paper;
public boolean paperRecycled;
public boolean plasticRecycled;
public boolean plastic;
public boolean glassRecycled;
public boolean glass;
public boolean cansRecycled;
public boolean cans;
public double canReductions;
public double glassReductions;
public double plasticReductions;
public double paperReductions;
public double netWasteReduction;
public double total;
CO2FromWaste(int numPeople, boolean paper, boolean plastic, boolean glass, boolean cans)
{
numPeople = numberOfPeople;
paper = paperRecycled;
plastic = plasticRecycled;
glass = glassRecycled;
cans = cansRecycled;
}
public double calcGrossWasteEmission(){
grossWasteEmission = numPeople * 1018;
return grossWasteEmission;
}
public double calcCanReductions() {
double can = 165.8;
if (cans){
canReductions = (can * numPeople);
}
return canReductions;
}
public double calcGlassReductions() {
double glassReduce = 46.6;
if(glass){
glassReductions = (glassReduce * numPeople);
}
return glassReductions;
}
public double calcPlasticReductions() {
double plasticReduce = 25.6;
if(plastic){
plasticReductions = (plasticReduce * numPeople);
}
return plasticReductions;
}
public double calcPaperReductions() {
double paperReduce = 184.0;
if(paper){
paperReductions = (paperReduce * numPeople);
}
return paperReductions;
}
public double calcNetWasteReduction(){
netWasteReduction = paperReductions + plasticReductions + glassReductions + canReductions;
return netWasteReduction;
}
public double total(){
total = grossWasteEmission - netWasteReduction;
return total;
}
}
import java.util.*;
public class CO2FromWasteTester
{
public static void main(String[] args){
ArrayList<CO2FromWasteTester> C02 = new ArrayList<CO2FromWasteTester>(5);
C02.add(new CO2FromWasteTester(1, true, true, true, true));
C02.add(new C02FootPrint(3, true, false, true, true));
C02.add(new C02FootPrint(4, false, false, false, false));
C02.add(new C02FootPrint(1, true, true, true, true));
C02.add(new C02FootPrint(1, true, true, true, true));
}
}
now it says that it cannot find my constructor CO2FromWasteTester(int,boolean,boolean,boolean,boolean)
#6
Re: Using an array list
Posted 09 November 2009 - 12:34 PM
Make it public.
((lol I accidentally said pubic lol))
((lol I accidentally said pubic lol))
#7
Re: Using an array list
Posted 09 November 2009 - 12:35 PM
I think you meant to put it C02FromWaste you have tester in there when you need it to be just waste. Cannot find constructor for it because your tester doesn't have a constructor, pretty sure you meant to put C02FromWaste not tester
I think you ned to put all of them C02FromWaste class, you haven't shown a C02Footprint class... so you need to change your arraylist to <C02FromWaste> C02
C02.add(new C02FromWaste(3, true, false, true, true));
Hope this helps
I think you ned to put all of them C02FromWaste class, you haven't shown a C02Footprint class... so you need to change your arraylist to <C02FromWaste> C02
C02.add(new C02FromWaste(3, true, false, true, true));
Hope this helps
This post has been edited by Fuzzyness: 09 November 2009 - 12:36 PM
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote







|