我需要顯示一個ArrayList,列出一個人可能擁有的大學學位。爲什麼我的代碼不顯示這2個Arraylist?
在另一個ArrayList中,我需要顯示符合公司要求的大學學位要求的個人列表。
在循環內嘗試了一個system.out,它甚至沒有訪問for循環。
* 2種方法與for循環在這個類
import java.util.ArrayList;
public class RecruitingCompany {
private String companyName;
private int phoneNumber;
private String address;
private ArrayList<CollegeDegree> collegeDegreeList = new ArrayList<>();
private ArrayList<Candidate> candidateList = new ArrayList<>();
private Candidate candidate;
private Requirement academicDegree;
public RecruitingCompany(){
/*main constructor*/
}
public RecruitingCompany(String companyName, int phoneNumber, String address){
this.companyName = companyName;
this.phoneNumber = phoneNumber;
this.address = address;
}
public String getCompanyName() {
return companyName;
}
public void setCompanyName(String companyName) {
this.companyName = companyName;
}
public int getPhoneNumber() {
return phoneNumber;
}
public void setPhoneNumber(int phoneNumber) {
this.phoneNumber = phoneNumber;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public ArrayList<CollegeDegree> getCollegeDegreeList() {
return collegeDegreeList;
}
public void setCollegeDegreeList(ArrayList<CollegeDegree> collegeDegreeList) {
this.collegeDegreeList = collegeDegreeList;
}
public ArrayList<Candidate> getCandidateList() {
return candidateList;
}
public void setCandidateList(ArrayList<Candidate> candidateList) {
this.candidateList = candidateList;
}
public Candidate getCandidate() {
return candidate;
}
public void setCandidate(Candidate candidate) {
this.candidate = candidate;
}
public Requirement getAcademicDegree() {
return academicDegree;
}
public void setAcademicDegree(Requirement academicDegree) {
this.academicDegree = academicDegree;
}
public String showCandidateCollegeDegrees(){
String degree = "Candidato: " + candidate.getName() + "\n";
for (CollegeDegree cd: this.collegeDegreeList){
degree += cd.toString();
}
return degree;
}
public String selectByCollegeDegree(){
String person = "Título: " + academicDegree.getDegree() + "\n";
for (Candidate c: this.candidateList){
person += c.toString();
}
return person;
}
}
的Tester類
public class Tester {
public static void main(String[] args) {
AvailableJob availableJob = new AvailableJob(2005, 2011, "Contador", 444464444, "Metalco", "del poste de luz, 50m oeste", 550.000);
Candidate candidate = new Candidate("Asdrubal", 888888888, "[email protected]", "Bachillerato");
CollegeDegree collegeDegree = new CollegeDegree("Bachillerato Administracion", 2003, "Universidad Aguila Calva");
RecruitingCompany recruitingCo = new RecruitingCompany();
Requirement requirement = new Requirement("Bachillerato", 4);
recruitingCo.setCandidate(candidate);
recruitingCo.setAcademicDegree(requirement);
availableJob.setRequirement(requirement);
System.out.println(recruitingCo.showCandidateCollegeDegrees());
System.out.println();
System.out.println(recruitingCo.selectByCollegeDegree());
System.out.println();
System.out.println(availableJob.showRequirement());
//System.out.print(recruitingCo.getCandidateList());
}
}
你從不向這些'ArrayList'添加任何東西。 – resueman
如何?我將它們添加到測試儀中。 – lingote
你正在設置'candidate'和'academicDegree'字段,但是那些不會修改'List'。如果你想,你需要在列表中調用'add'方法(例如,在你的'setCandidate'方法內部)。 – resueman