Q4. Consider the following code snippet.
[CO5]
[3]
a. Identify at least 3 code smells from the below code and name them.
b. Refractor the source code to remove 4 different Code smells( write the code segment in your
copy which has code smell and then show the correct way to refactor it).
NB: The "System.out.println" statements should not cause any smells
[4.5]
public abstract class Education{
}
public void provideQualityEducation();
public void takeClasses();
public void checkExamScripts();
public class Student extends Education{
public String studentName;
public String studentId;
public String department;
public String enrollmentDate;
public int totalCreditCompleted;
public double currentCGPA;
public String semester;
public String InternationalPolitics = "no politics";
public void setStudentDetails(String studentName,
{
String studentId, String department,
String enrollmentDate,
double totalCreditCompleted,
double currentCGPA, String semester)
this.studentName = studentName;
this.studentId = studentId;
this.department = department;
this.enrollmentDate = enrollmentDate;
this.totalCreditCompleted = totalCreditCompleted;
this.currentCGPA = currentCGPA;
this.semester = semester;
}
//below method is for showing student Details
public void meritBasedScholarship() {
collectStudentsInformation();
getStudentsSemesterDetails();
System.out.println("Student Name: " + this.x);
System.out.println("Student ID: " + this.studentId);
System.out.println("Department: " + this.y);
System.out.println("Enrollment Date: " + this.z);
}
public class Teacher
{
public String teacherName;
public String teacherID;;
public String InternationalPolitics = "no
politics";
public void setTeacherDetails (String
teacherName, String teacherID)
{
this.teacherName = teacherName;
this.teacherName = teacherID;
}
}
}