User Story
As a teacher, I want to be able to manage student information in a system so that I can easily access and display their details whenever needed.
Acceptance Criteria:
- The system should allow the creation of a student object with a name and age.
- The student object should have the name and age fields as final variables.
- The system should provide a method to display the student's details.
- The display method should print the student's name and age.
- The system should prevent any modification of the student's name and age after initialization.
- The system should be implemented using the Apex programming language.
Solution
Student Class:
public class Student {
private final String name;
private final Integer age;
public Student(String name, Integer age) {
this.name = name;
this.age = age;
}
public void displayDetails() {
System.debug('Student Details:');
System.debug('Name: ' + name);
System.debug('Age: ' + age);
}
}
Apex Code:
Student student = new Student('John Doe', 20);
student.displayDetails();