我剛剛進入Java,我很快就要爲我的課程準備一個項目,並繼續運行相同的錯誤。我要創建一個學生,教師,員工目錄,可以添加新條目,更新它們,並使用String()方法打印它們。我被推薦使用一個treeMap集合。錯誤涉及.getKey()方法,無法找到它。我將包括我的代碼,並將非常感謝任何意見,以幫助我弄清楚這一點。先謝謝你。Java中的學生,教師,職員目錄
import java.util.TreeMap;
import java.util.*;
import java.util.Map.Entry;
import java.util.Iterator;
import java.util.Map;
/**
* Write a description of class Persons here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Directory {
private String firstName, lastName;
private TreeMap<String, Persons> schoolDirectory;
private int numberInDirectory;
public Directory() {
schoolDirectory = new TreeMap<String, Persons>();
}
public String getKey() {
return lastName + firstName;
}
public void addPerson(Persons newPersons) {
schoolDirectory.put(Persons.getKey(), newPersons);
numberInDirectory++;
}
public void addPerson(Staff newStaff) {
schoolDirectory.put(newStaff.getKey(), newStaff);
numberInDirectory++;
}
public int getNumber() {
return numberInDirectory;
}
public class Persons {
// instance variables - replace the example below with your own
private String firstName;
private String lastName;
private String email;
}
}
/**
* Write a description of class People here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class People extends Directory {
private String firstName, lastName, emailAddress, phoneNumber, ID;
public People(String firstName, String lastName, String emailAddress, String phoneNumber, String ID) {
this.firstName = firstName;
this.lastName = lastName;
this.emailAddress = emailAddress;
this.phoneNumber = phoneNumber;
this.ID = ID;
}
public String getKey() {
return lastName + firstName;
}
}
/**
* Write a description of class Students here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Students extends People {
// instance variables - replace the example below with your own
private String classlevel;
private int SudentID;
}
/**
* Write a description of class Faculty here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Faculty extends People {
private String RoomNumber;
private String EmployeeStatus;
private String ProgramOfInstruction;
public Faculty(String firstName, String lastName, String emailAddress, String phoneNumber, String ID, String room, String status, String instruction) {
super(firstName, lastName, emailAddress, phoneNumber, ID);
RoomNumber = room;
EmployeeStatus = status;
ProgramOfInstruction = instruction;
}
}
/**
* Write a description of class Staff here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Staff extends People {
private String OfficeNumber;
private String JobTitle;
public Staff(String firstName, String lastName, String emailAddress, String phoneNumber, String ID, String office, String position) {
super(firstName, lastName, emailAddress, phoneNumber, ID);
OfficeNumber = office;
JobTitle = position;
}
}
你得到的* exact *錯誤信息是什麼? – awksp
無法找到符號 - 方法getKey() – user3758442
您已經張貼了太多的代碼。請閱讀[如何創建一個最小,完整和可驗證的示例](http://stackoverflow.com/help/mcve)指出發生此錯誤的位置也很方便。 – PakkuDon