6 Replies - 948 Views - Last Post: 09 November 2009 - 12:35 PM Rate Topic: -----

#1 gibson.nathan  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 8
  • View blog
  • Posts: 294
  • Joined: 06-October 09

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
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));

		   
	}
		   
		   
		
}



Is This A Good Question/Topic? 0
  • +

Replies To: Using an array list

#2 NeoTifa  Icon User is offline

  • Whorediot
  • member icon





Reputation: 2637
  • View blog
  • Posts: 15,663
  • Joined: 24-September 08

Re: Using an array list

Posted 09 November 2009 - 12:08 PM

Did you import java.util.*?
Was This Post Helpful? 0
  • +
  • -

#3 gibson.nathan  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 8
  • View blog
  • Posts: 294
  • Joined: 06-October 09

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));

		   
	}
		   
		   
		
}


Was This Post Helpful? 0
  • +
  • -

#4 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1639
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Using an array list

Posted 09 November 2009 - 12:15 PM

I could be wrong but I think this line is your issue:

C02.add(new (1, true, true, true, true));



Shouldnt it be

C02.add(new C02FootPrint(1, true, true, true, true));


Was This Post Helpful? 0
  • +
  • -

#5 gibson.nathan  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 8
  • View blog
  • Posts: 294
  • Joined: 06-October 09

Re: Using an array list

Posted 09 November 2009 - 12:24 PM

im working the error around. i have two classes.
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)
Was This Post Helpful? 0
  • +
  • -

#6 NeoTifa  Icon User is offline

  • Whorediot
  • member icon





Reputation: 2637
  • View blog
  • Posts: 15,663
  • Joined: 24-September 08

Re: Using an array list

Posted 09 November 2009 - 12:34 PM

Make it public.

((lol I accidentally said pubic lol))
Was This Post Helpful? 1
  • +
  • -

#7 Fuzzyness  Icon User is offline

  • Comp Sci Student
  • member icon

Reputation: 669
  • View blog
  • Posts: 2,438
  • Joined: 06-March 09

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

This post has been edited by Fuzzyness: 09 November 2009 - 12:36 PM

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1