Reputation: 47
Eclipse is telling me "undefined for the type Chore" for getName() on the last line. I am not understanding where the problem is. I also have a Chore class, so is it trying to pull Name from the Chore class? Or is there something wrong in my People class? (added the Chore class also)
System.out.printf("%s's Chores: %n", person.getName());
for(int i=0; i<person.getNumChores(); i++) {
System.out.println(person.getChores()[i].getName()); //error here
}
People class:
public class People {
private Chore chores[] = new Chore[48];
private int numChores = 0;
private final String name;
private final int birthYear;
private int age;
public void addChore(Chore chore) {
if(numChores == 48) {
System.out.println("All chores have been assigned.");
}
else {
chores[numChores++] = chore;
}
}
public People(String name, int birthYear, int age) {
this.name = name;
this.birthYear = birthYear;
this.age = age;
}
public String getName() {
return name;
}
public int getBirthYear() {
return birthYear;
}
public int setAge(int birthYear) {
int age = 2020 - birthYear;
return age;
}
public int getAge(){
return age;
}
public int getNumChores() {
return numChores;
}
public Chore[] getChores() {
return chores;
}
}
Here is the Chore class:
public class Chore{
private final String choreName;
private final String difficulty;
private final String timesPerWeek;
private String location;
private String assigned;
public Chore(String location, String choreName, String timesPerWeek, String difficulty){
this.location = location;
this.choreName = choreName;
this.timesPerWeek = timesPerWeek;
this.difficulty = difficulty;
this.assigned = "N";
}
public Chore(String choreName, String timesPerWeek, String difficulty){
this(choreName, timesPerWeek, difficulty, "Whole house");
this.assigned = "N";
}
public String getChoreName(){
return choreName;
}
public String getDifficulty(){
return difficulty;
}
public String getTimesPerWeek(){
return timesPerWeek;
}
public String getLocation(){
return location;
}
public String setAssigned(){
String assigned = "Y";
return assigned;
}
public String getAssigned(){
return assigned;
}
}
Upvotes: 0
Views: 48
Reputation: 79620
You do not have getName()
method inside Chore
.
Replace
System.out.println(person.getChores()[i].getName());
with
System.out.println(person.getChores()[i].getChoreName());
Upvotes: 1