I just have a basic Class encapulating foods, and when i go to my client class to check the method getName
, String and all the other methods, it all returns null. Not sure what is wrong here.
public class Foods {
public String name;
public int calPerServing;
public int servingPerContainer;
Foods(String n, int c, int s){
n = name;
c = calPerServing;
s = servingPerContainer;
}
@Override
public String toString() {
return "Name: " + name + "\nCalories Per Serving: " + calPerServing
+ "\nServings Per Container: " + servingPerContainer;
}
public String getName() {
return name;
}
public int getCalPerServing() {
return calPerServing;
}
public int getServingPerContainer() {
return servingPerContainer;
}
public int getTotalCalories(){
return (calPerServing * servingPerContainer);
}
}
public class Client {
public static void main(String[] args) {
Foods chips = new Foods("chips", 10, 1);
System.out.println(chips.getName());
}
}