Browse Source

refactoring: adjusting variables naming Convention to avoid confusion

remotes/origin/fdai7780
Tobias Herbert 11 months ago
parent
commit
9ac92b1fcf
  1. 4
      src/main/java/org/example/Administration.java
  2. 44
      src/main/java/org/example/Student.java
  3. 8
      src/test/java/org/example/AdministrationTest.java
  4. 6
      src/test/java/org/example/StudentTest.java

4
src/main/java/org/example/Administration.java

@ -196,7 +196,7 @@ public class Administration {
*/
public boolean deleteStudents(String studentID){
for(Student student : students){
if(student.getId().equals(studentID)){
if(student.getStudentId().equals(studentID)){
students.remove(student);
return true;
}
@ -223,7 +223,7 @@ public class Administration {
{
for(Student student :students)
{
if(student.getId().equals(studentId))
if(student.getStudentId().equals(studentId))
{
return student;
}

44
src/main/java/org/example/Student.java

@ -9,9 +9,9 @@ import java.util.List;
*/
public class Student {
String name;
String id;
String role;
String studentName;
String studentId;
String studentRole;
public Student(){
@ -25,33 +25,33 @@ public class Student {
* @param role the role of the student in the system (should typically be "Student")
*/
this.name = name;
this.id = id;
this.role = role;
this.studentName = name;
this.studentId = id;
this.studentRole = role;
}
public String getName() {
return name;
public String getStudentName() {
return studentName;
}
public String getId() {
return id;
public String getStudentId() {
return studentId;
}
public String getRole() {
return role;
public String getStudentRole() {
return studentRole;
}
public void setName(String name) {
this.name = name;
public void setStudentName(String studentName) {
this.studentName = studentName;
}
public void setId(String id) {
this.id = id;
public void setStudentId(String studentId) {
this.studentId = studentId;
}
public void setRole(String role) {
this.role = role;
public void setStudentRole(String studentRole) {
this.studentRole = studentRole;
}
/**
@ -61,15 +61,15 @@ public class Student {
public void printStudentInfo()
{
System.out.println("Name: " + getName());
System.out.println("ID: " + getId());
System.out.println("Role: " + getRole());
System.out.println("Name: " + getStudentName());
System.out.println("ID: " + getStudentId());
System.out.println("Role: " + getStudentRole());
}
public void writeToFile(Student student, String filename) throws IOException {
try(BufferedWriter writer = new BufferedWriter(new FileWriter(filename))){
String attributes = student.getName() + "\n" + student.getId() + "\n" + student.getRole();
String attributes = student.getStudentName() + "\n" + student.getStudentId() + "\n" + student.getStudentRole();
writer.write(attributes);
}

8
src/test/java/org/example/AdministrationTest.java

@ -167,7 +167,7 @@ class AdministrationTest {
// Now, the student should be found
assertNotNull(administration.findStudentById("S1001"));
assertEquals("Alice", administration.findStudentById("S1001").getName());
assertEquals("Alice", administration.findStudentById("S1001").getStudentName());
}
@Test
@ -205,13 +205,13 @@ class AdministrationTest {
assertNotNull(retrievedStudent);
// Asserting that the retrieved student's name matches the expected name
assertEquals("Walter White", retrievedStudent.getName());
assertEquals("Walter White", retrievedStudent.getStudentName());
// Asserting that the retrieved student's ID matches the expected ID
assertEquals("S123456", retrievedStudent.getId());
assertEquals("S123456", retrievedStudent.getStudentId());
// Asserting that the retrieved student's role matches the expected role
assertEquals("Student", retrievedStudent.getRole());
assertEquals("Student", retrievedStudent.getStudentRole());
}
/**

6
src/test/java/org/example/StudentTest.java

@ -61,9 +61,9 @@ class StudentTest {
assertEquals(1, testStudents.size());
Student admin = testStudents.get(0);
assertEquals("Sebastian Reichard", admin.getName());
assertEquals("S1001", admin.getId());
assertEquals("Student", admin.getRole());
assertEquals("Sebastian Reichard", admin.getStudentName());
assertEquals("S1001", admin.getStudentId());
assertEquals("Student", admin.getStudentRole());
// Files.delete(Path.of(filename));

Loading…
Cancel
Save