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

1. Lecturer java code to answer the question ***********************************

ID: 643783 • Letter: 1

Question

1. Lecturer java code to answer the 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;
    }
} //end class

*******************************************

The Lecturer.java class is a simple class that does not explicitly inherit from any other classes, it defaults from the Object class in java.lang by default. This means it inherits all of Object

Explanation / Answer

import java.util.ArrayList;

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

    //overided equals method
    @Override
       public boolean equals(Object obj) {
       Lecturer lecturer=(Lecturer)obj;
    if(this.familyName.equals(lecturer.familyName)&&this.firstName.equals(lecturer.firstName)&&this.phoneNo==lecturer.phoneNo&&this.title.equals(lecturer.title))
       return true;
    else
       return false;
       }
  
  
  
    public String toString ()
    { String toScreen ;
        toScreen = " " + title + " " + firstName + " " + familyName ;
        toScreen += " Phone: " + phoneNo ;
        return toScreen;
    }
  

    public static void main(String[] args) {
      
       Lecturer lecturer=new Lecturer("firstNameIn", "familyNameIn", 87654, "titleIn");
       Lecturer lecturer1=new Lecturer("firstNameIn1", "familyNameIn1", 87654, "titleIn1");
       Lecturer lecturer2=new Lecturer("firstNameIn2", "familyNameIn2", 87655, "titleIn2");
       ArrayList<Lecturer> arrayList=new ArrayList<>();
       arrayList.add(lecturer);
       arrayList.add(lecturer1);
       arrayList.add(lecturer2);
       System.out.println(arrayList.toString());
      
   }
}