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

1. Shown is the code for a class Lecturer for use in this question. //**********

ID: 3552435 • Letter: 1

Question

1. Shown is the code for a class Lecturer for use in this question.

//********************************************************

// Lecturer.java A class to represent a lecturer at University

//********************************************************

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;

}

} //end class



Write a test program that creates several instances of class Lecturer and stores them in an array called staff List. When the program prints out the staff List it should look like:- Write code to printout ONLY the phone numbers of the lecturers in the staff List as shown. Finally, write code to allow you to change the title of your current lecturer to "Professor" stored in the staff List and print out the result as shown.

Explanation / Answer

    public static void main(String [] args){
        Lecturer l1 = new Lecturer("Anna", "Vanibles", 991952, "Dr");
        Lecturer l2 = new Lecturer("DAnna", "jsdfk", 992421952, "Dr");
        Lecturer l3 = new Lecturer("KAnna", "jsfka", 996781, "Ms");
        Lecturer []staffList = {l1,l2,l3};
    }
   
    public static void printArray(Lecturer[] staffList){
        for (int i = 0; i < staffList.length; i++) {
            System.out.println(staffList[i].toString());
        }
    }
   
    public static void printMobileNumbers(Lecturer[] staffList){
        System.out.println("Phone numbers:-");
        for (int i = 0; i < staffList.length; i++) {
            System.out.println(staffList[i].phoneNo);
        }
    }


   public void setTitle (String titleIn ) {
    title = titleIn ;
    }