I'm attempting to create objects of my Profile class and store them in an arrayList created in a ProfileCollector class I created.
import java.util.ArrayList;
public class ProfileCollector
{
private ArrayList<Profile> profileList;
public ProfileCollector()
{
profileList = new ArrayList<Profile>();
//peopleList = new ArrayList<String>();
}
public void addProfile(String initName, int initKcalTotal, int initProteinTotal, int initFatTotal){
profileList.add(new Profile(initName, initKcalTotal, initProteinTotal, initFatTotal));
}
}
Here is my profile class:
import java.util.ArrayList;
public class Profile
{
private ArrayList<DailyIntake> nutritionalStats;
private String name;
private int kcalTotal;
private int proteinTotal;
private int fatTotal;
//These values represent nutritional requirements
public Profile(String initName, int initKcalTotal, int initProteinTotal, int initFatTotal)
{
name = initName;
kcalTotal = initKcalTotal;
proteinTotal = initProteinTotal;
fatTotal = initFatTotal;
}
public String getName(){
return name;
}
public int getKcalTotal(){
return kcalTotal;
}
public int getProteinTotal(){
return proteinTotal;
}
public int getFatTotal(){
return fatTotal;
}
}
Here are the parts of my main.java that are important
public static void main(String[] args) {
ProfileCollector profiles = new ProfileCollector();
//theres also a line that calls to a method which calls to another method with this line: profiles.addProfile(new Profile(name, optimumCalories, optimumProteins, optimumFats));
}
The error message is that the variable profiles is cannot be found. My question is also if I am correctly creating objects and adding them to an ArrayList. I didn't know if creating a class was the best way to go about this, but it was the way I've partial seen before. Anything helps.
Here is the error message:
error: cannot find symbol profiles.addProfile(new Profile(name, optimumCalories, optimumProteins, optimumFats)); ^ symbol: variable profiles location: class Main