From 740beafb4be79e55edd4e0448ab589a088ce76db Mon Sep 17 00:00:00 2001 From: Tobias Herbert Date: Thu, 8 Feb 2024 16:25:35 +0100 Subject: [PATCH] refactoring: adjusting variables naming Convention to avoid confusion --- src/main/java/org/example/Admin.java | 44 +++++++++---------- src/main/java/org/example/Administration.java | 4 +- src/test/java/org/example/AdminTest.java | 6 +-- .../java/org/example/AdministrationTest.java | 6 +-- 4 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/main/java/org/example/Admin.java b/src/main/java/org/example/Admin.java index f8ad460..309feed 100644 --- a/src/main/java/org/example/Admin.java +++ b/src/main/java/org/example/Admin.java @@ -8,9 +8,9 @@ import java.util.List; * Represents an administrative user in the system. */ public class Admin { - public String name; - public String id; - public String role; + public String adminName; + public String adminId; + public String adminRole; public Admin() { } @@ -22,29 +22,29 @@ public class Admin { * @param role the role of the admin in the system (should typically be "Admin") */ public Admin(String name, String id, String role) { - this.name = name; - this.id = id; - this.role = role; + this.adminName = name; + this.adminId = id; + this.adminRole = role; } - public String getName() { - return name; + public String getAdminName() { + return adminName; } - public void setName(String name) { - this.name = name; + public void setAdminName(String adminName) { + this.adminName = adminName; } - public String getId() { - return id; + public String getAdminId() { + return adminId; } - public void setId(String id) { - this.id = id; + public void setAdminId(String adminId) { + this.adminId = adminId; } - public String getRole() { - return role; + public String getAdminRole() { + return adminRole; } - public void setRole(String role) { - this.role = role; + public void setAdminRole(String adminRole) { + this.adminRole = adminRole; } /** @@ -53,9 +53,9 @@ public class Admin { */ public void printAdminInfo() { - System.out.println("Name: " + getName()); - System.out.println("ID: " + getId()); - System.out.println("Role: " + getRole()); + System.out.println("Name: " + getAdminName()); + System.out.println("ID: " + getAdminId()); + System.out.println("Role: " + getAdminRole()); } /** @@ -65,7 +65,7 @@ public class Admin { */ public void writeToFile(Admin admin, String filename) throws IOException{ try(BufferedWriter writer = new BufferedWriter(new FileWriter(filename))){ - String attributes = admin.getName() + "\n" + admin.getId() + "\n" + admin.getRole(); + String attributes = admin.getAdminName() + "\n" + admin.getAdminId() + "\n" + admin.getAdminRole(); writer.write(attributes); } diff --git a/src/main/java/org/example/Administration.java b/src/main/java/org/example/Administration.java index 03aa389..0041c76 100644 --- a/src/main/java/org/example/Administration.java +++ b/src/main/java/org/example/Administration.java @@ -153,7 +153,7 @@ public class Administration { { for(Admin admin : admins ) { - if(admin.getId().equals(adminID)){ + if(admin.getAdminId().equals(adminID)){ admins.remove(admin); return true; //Course found and removed } @@ -181,7 +181,7 @@ public class Administration { { for(Admin admin :admins) { - if(admin.getId().equals(adminId)) + if(admin.getAdminId().equals(adminId)) { return admin; } diff --git a/src/test/java/org/example/AdminTest.java b/src/test/java/org/example/AdminTest.java index 40104f9..890fed2 100644 --- a/src/test/java/org/example/AdminTest.java +++ b/src/test/java/org/example/AdminTest.java @@ -74,9 +74,9 @@ class AdminTest { assertEquals(1, testAdmins.size()); Admin admin = testAdmins.get(0); - assertEquals("Thomas", admin.getName()); - assertEquals("A1001", admin.getId()); - assertEquals("Admin", admin.getRole()); + assertEquals("Thomas", admin.getAdminName()); + assertEquals("A1001", admin.getAdminId()); + assertEquals("Admin", admin.getAdminRole()); } } \ No newline at end of file diff --git a/src/test/java/org/example/AdministrationTest.java b/src/test/java/org/example/AdministrationTest.java index 1dc593f..a98f761 100644 --- a/src/test/java/org/example/AdministrationTest.java +++ b/src/test/java/org/example/AdministrationTest.java @@ -139,8 +139,8 @@ class AdministrationTest { Admin result = administration.findAdminById("A2001"); assertNotNull(result, "Admin should be found after being added."); - assertEquals("A2001", result.getId(), "The ID of the found admin should match."); - assertEquals("Jane Doe", result.getName(), "The name of the found admin should match."); + assertEquals("A2001", result.getAdminId(), "The ID of the found admin should match."); + assertEquals("Jane Doe", result.getAdminName(), "The name of the found admin should match."); } @Test @@ -151,7 +151,7 @@ class AdministrationTest { Admin result = administration.findAdminById("A2002"); assertNotNull(result, "Admin should be found by ID."); - assertEquals("A2002", result.getId(), "The ID should match the one searched for."); + assertEquals("A2002", result.getAdminId(), "The ID should match the one searched for."); } @Test