Browse Source

refactoring: adjusting variables naming Convention to avoid confusion

remotes/origin/fdai7780
Tobias Herbert 11 months ago
parent
commit
740beafb4b
  1. 44
      src/main/java/org/example/Admin.java
  2. 4
      src/main/java/org/example/Administration.java
  3. 6
      src/test/java/org/example/AdminTest.java
  4. 6
      src/test/java/org/example/AdministrationTest.java

44
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);
}

4
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;
}

6
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());
}
}

6
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

Loading…
Cancel
Save