Welche Klasse verursacht Fehler „für den Typ nicht definiert“?

Yep:

Eclipse sagt mir für getName „für den Typ Chore undefiniert“ () in der letzten Zeile. Ich verstehe nicht, wo das Problem ist. Ich habe auch eine Chore Klasse wird so versucht, Namen von der Chore Klasse zu ziehen? Oder ist es etwas falsch in meinem Menschen Klasse? (Addierte auch die Chore-Klasse)

        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
        }

Menschen Klasse:

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

Hier ist die Chore Klasse:

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;
    }
}
Arvind Kumar Avinash:

Sie haben keine getName()Methode innen Chore.

Ersetzen

System.out.println(person.getChores()[i].getName());

mit

System.out.println(person.getChores()[i].getChoreName());

Ich denke du magst

Origin http://10.200.1.11:23101/article/api/json?id=378885&siteId=1
Empfohlen
Rangfolge