Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

public class Lecturer { private String firstName ; private String familyName ; p

ID: 3552939 • Letter: P

Question


public class Lecturer {


private String firstName ;

private String familyName ;

private int phoneNo ;

private String title ;

public Lecturer (String firstNameIn, String familyNameIn, int phoneNoIn,

String titleIn)

{ firstName = firstNameIn ;

familyName = familyNameIn ;

phoneNo = phoneNoIn ;

title = titleIn ;

}

public String getFamilyName ( )

{ return familyName;

}

public int getPhoneNo ( )

{ return phoneNo ;

}

public void setTitle (String titleIn )

{ title = titleIn ;

}

public String toString ()

{ String toScreen ;

toScreen = " " + title + " " + firstName + " " + familyName ;

toScreen += " Phone: " + phoneNo ;

return toScreen;

}




}



_______________________________________________________________________________________



public class LecturerTest

{

public static void main (String [] args )

{


Lecturer anne = new Lecturer ( "Anne", "Venables", 99195209, "Ms") ;

Lecturer dan = new Lecturer ( "Dan", "Nelson", 99194839, "Mr") ;

Lecturer jakub = new Lecturer ( "Jakub", "Szajman", 99194286, "Dr") ;

Lecturer grace = new Lecturer ( "Grace", "Tan", 99194685, "Course coordinator") ;


System.out.println ( "***************************************" ) ;

System.out.println("Phone Numbers:- ");

Lecturer [ ] staffLists = new Lecturer [4] ;

staffLists [ 0 ] = anne ;

staffLists [ 1 ] = dan;

staffLists [ 2 ] = jakub;

staffLists [ 3 ] = grace;


for (int index = 0 ; index< staffLists.length ; index++)

System.out.println ( staffLists[index] .toString( )) ;


}


//public static void printphoneNumbers(Lecturer[] staffList)

{

System.out.println("Phone: ");


}


}



Write code to printout ONLY the phone numbers of the lecturers in the staffList as shown. Finally, write code to allow you to change the title of your current lecturer to "Professor" stored in the staffList and print out the result as shown.

Explanation / Answer

public class Lecturer {


private String firstName ;

private String familyName ;

private int phoneNo ;

private String title ;



public Lecturer (String firstNameIn, String familyNameIn, int phoneNoIn,

String titleIn)

{ firstName = firstNameIn ;

familyName = familyNameIn ;

phoneNo = phoneNoIn ;

title = titleIn ;

}

public String getFirstName()
{
    return firstName;
}

public String getFamilyName ( )

{ return familyName;

}



public int getPhoneNo ( )

{ return phoneNo ;

}



public void setTitle (String titleIn )

{ title = titleIn ;

}



public String toString ()

{ String toScreen ;

toScreen = " " + title + " " + firstName + " " + familyName ;

toScreen += " Phone: " + phoneNo ;

return toScreen;

}

}



------------------------------------------------------------------------------------------------------------






public class LecturerTest

{

public static void main (String [] args )

{


Lecturer anne = new Lecturer ( "Anne", "Venables", 99195209, "Ms") ;

Lecturer dan = new Lecturer ( "Dan", "Nelson", 99194839, "Mr") ;

Lecturer jakub = new Lecturer ( "Jakub", "Szajman", 99194286, "Dr") ;

Lecturer grace = new Lecturer ( "Grace", "Tan", 99194685, "Course coordinator") ;


System.out.println ( "***************************************" ) ;



Lecturer [ ] staffLists = new Lecturer [4] ;

staffLists [ 0 ] = anne ;

staffLists [ 1 ] = dan;

staffLists [ 2 ] = jakub;

staffLists [ 3 ] = grace;


// for (int index = 0 ; index< staffLists.length ; index++)

// System.out.println ( staffLists[index] .toString( )) ;

printphoneNumbers(staffLists);
changeTitle(staffLists,staffLists[0]);
}


public static void printphoneNumbers(Lecturer[] staffList)
{
System.out.println("Phone numbers:- ");
for (int index = 0 ; index< staffList.length ; index++)
System.out.println ( staffList[index].getPhoneNo()) ;

System.out.println("");
}

public static void changeTitle(Lecturer[] staffList,Lecturer currentLecturer)
{
    for (int index = 0 ; index< staffList.length ; index++)
    {
        if(staffList[index].getFirstName()==currentLecturer.getFirstName())
        {
            staffList[index].setTitle("Professor");
            System.out.print("A Promotion for "+staffList[index].getFirstName()+" ");
            System.out.println ( staffList[index] .toString( )) ;
        }

       
    }
}
}