lingote
lingote

Reputation: 133

Why is my code not displaying these 2 Arraylists?

I need to display an ArrayList with a list of college degree/s that an individual may have.

In another ArrayList, I need display the list of individual/s that meet the requirement of college degree that a company is asking.

Tried a system.out inside the loops and it's not even accessing the for loops.

*The 2 methods with the for loops are at the end of this class

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

}

The Tester class

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

}

Upvotes: 2

Views: 115

Answers (2)

rc-chandan
rc-chandan

Reputation: 601

You are not adding the new candidate or degree to the arraylists. Change the following methods it will work,

public void setAcademicDegree(Requirement academicDegree) {
    this.academicDegree = academicDegree;
    collegeDegreeList.add(academicDegree);
}

and

public void setCandidate(Candidate candidate) {
    this.candidate = candidate;
    candidateList.add(candidate);
}

Now when you set a new Candidate object or CollegeDegree object it will be automatically added to the lists.

Upvotes: 2

Slava Vedenin
Slava Vedenin

Reputation: 60104

In your code, you need to do some changes:

  1. setCollegeDegreeList(), setCandidateList() and setCandidate() methods should be changed to addCollegDegree() and addCandidate()
  2. recruitingCo.setCandidate(candidate) should be replaced to recruitingCo.addCandidate(candidate);
  3. Need to add recruitingCo.addCollegeDegree(collegeDegree); in main();

And you can get following code:

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 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 ArrayList<Candidate> getCandidateList() {
    return candidateList;
}

public void addCollegeDegree(CollegeDegree collegeDegree) {
    this.collegeDegreeList.add(collegeDegree);
}

public void addCandidate(Candidate candidate) {
    this.candidateList.add(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.addCandidate(candidate); 
    recruitingCo.addСollegeDegree(collegeDegree); 

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

}

Upvotes: 0

Related Questions