Answer:
Complete solution is given below:
Explanation:
//student class
class Student{
private String firstname,lastname;
//constructor
Student(String first,String last){
this.firstname=first;
this.lastname=last;
}
//getters and setters
public String getFirstname() {
return firstname;
}
public void setFirstname(String firstname) {
this.firstname = firstname;
}
public String getLastname() {
return lastname;
}
public void setLastname(String lastname) {
this.lastname = lastname;
}
//function to get the fullname of student
public String fullName() {
return this.firstname+" "+this.lastname;
}
}
//class for line at office hour
class LineAtOfficeHour{
private Student line[];
private int N=0;
private int back=0;
//empty constructor
LineAtOfficeHour() {
line=new Student[5];
}
//parameterized constructor
LineAtOfficeHour(Student st[]) {
int i=0;
line=new Student[5];
while(i<st.length && i<5) {
line[i]=st[i];
i++;
}
this.N=i;
this.back=i-1;
}
//function to check if line is empty or not
public boolean isEmpty() {
if(this.N==0)
return true;
else
return false;
}
//function to check if line is full
public boolean isFull() {
if(this.N==5) {
return true;
}else
return false;
}
///function to get the size of line
public int size() {
return this.N;
}
//function to add a student to the line
public void enterLine(Student s) {
if(isFull())
System.out.println("Line is full!!!!");
else {
line[++back]=s;
this.N++;
}
}
public Student seeTeacher() {
Student result=null;
if(this.N>=0) {
result=line[0];
int i=0;
for(i=1;i<N;i++) {
line[i-1]=line[i];
}
line[i-1]=null;
this.N--;
this.back--;
}
return result;
}
//function to print students in line
public String whosInLine() {
String result ="";
for(int i=0;i<this.N;i++) {
result+=line[i].fullName()+",";
}
return result;
}
}
//driver method
public class TestLine {
public static void main(String[] args) {
LineAtOfficeHour list=new LineAtOfficeHour();
if(list.isEmpty()) {
System.out.println("Line is empty!!!!!!!!!");
}
Student s1[]=new Student[3];
s1[0]=new Student("John","Smith");
s1[1]=new Student("Sam","Zung");
s1[2]=new Student("Peter","Louis");
list=new LineAtOfficeHour(s1);
if(list.isEmpty()) {
System.out.println("Line is empty!!!!!!!!!");
}else {
System.out.println("Line is not empty.........");
}
System.out.println("Students in line: "+list.whosInLine());
System.out.println("Student removed: "+list.seeTeacher().fullName());
System.out.println("Students in line: "+list.whosInLine());
}
}