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
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 ;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.