Browse Source

Merge branch 'fdai7780'

remotes/origin/fdai7780
Tobias Herbert 11 months ago
parent
commit
1bd483bbf8
  1. 44
      src/main/java/org/example/Admin.java
  2. 8
      src/main/java/org/example/Administration.java
  3. 44
      src/main/java/org/example/Student.java
  4. 12
      src/test/java/org/example/AdminTest.java
  5. 14
      src/test/java/org/example/AdministrationTest.java
  6. 10
      src/test/java/org/example/StudentTest.java

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

@ -8,9 +8,9 @@ import java.util.List;
* Represents an administrative user in the system. * Represents an administrative user in the system.
*/ */
public class Admin { public class Admin {
public String name;
public String id;
public String role;
public String adminName;
public String adminId;
public String adminRole;
public Admin() { public Admin() {
} }
@ -22,29 +22,29 @@ public class Admin {
* @param role the role of the admin in the system (should typically be "Admin") * @param role the role of the admin in the system (should typically be "Admin")
*/ */
public Admin(String name, String id, String role) { 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() 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{ public void writeToFile(Admin admin, String filename) throws IOException{
try(BufferedWriter writer = new BufferedWriter(new FileWriter(filename))){ 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); writer.write(attributes);
} }

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

@ -153,7 +153,7 @@ public class Administration {
{ {
for(Admin admin : admins ) for(Admin admin : admins )
{ {
if(admin.getId().equals(adminID)){
if(admin.getAdminId().equals(adminID)){
admins.remove(admin); admins.remove(admin);
return true; //Course found and removed return true; //Course found and removed
} }
@ -181,7 +181,7 @@ public class Administration {
{ {
for(Admin admin :admins) for(Admin admin :admins)
{ {
if(admin.getId().equals(adminId))
if(admin.getAdminId().equals(adminId))
{ {
return admin; return admin;
} }
@ -196,7 +196,7 @@ public class Administration {
*/ */
public boolean deleteStudents(String studentID){ public boolean deleteStudents(String studentID){
for(Student student : students){ for(Student student : students){
if(student.getId().equals(studentID)){
if(student.getStudentId().equals(studentID)){
students.remove(student); students.remove(student);
return true; return true;
} }
@ -223,7 +223,7 @@ public class Administration {
{ {
for(Student student :students) for(Student student :students)
{ {
if(student.getId().equals(studentId))
if(student.getStudentId().equals(studentId))
{ {
return student; return student;
} }

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

@ -9,9 +9,9 @@ import java.util.List;
*/ */
public class Student { public class Student {
String name;
String id;
String role;
String studentName;
String studentId;
String studentRole;
public Student(){ public Student(){
@ -25,33 +25,33 @@ public class Student {
* @param role the role of the student in the system (should typically be "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() 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 { public void writeToFile(Student student, String filename) throws IOException {
try(BufferedWriter writer = new BufferedWriter(new FileWriter(filename))){ 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); writer.write(attributes);
} }

12
src/test/java/org/example/AdminTest.java

@ -30,7 +30,7 @@ class AdminTest {
//Tests printAdminInfo Method //Tests printAdminInfo Method
@org.junit.jupiter.api.Test @org.junit.jupiter.api.Test
void printAdminInfo() {
void testPrintAdminInfo() {
Admin admin = new Admin("Aaron", "A1001", "Admin"); Admin admin = new Admin("Aaron", "A1001", "Admin");
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
@ -47,7 +47,7 @@ class AdminTest {
} }
//Tests writeToFile Method //Tests writeToFile Method
@Test @Test
void writeToFile() throws IOException {
void testWriteToFile() throws IOException {
Admin admin = new Admin("Simon", "A1001", "Admin") ; Admin admin = new Admin("Simon", "A1001", "Admin") ;
admin.writeToFile(admin, fileName()); admin.writeToFile(admin, fileName());
@ -59,7 +59,7 @@ class AdminTest {
} }
//Tests readFromFile Method //Tests readFromFile Method
@Test @Test
void readFromFile() throws IOException {
void testReadFromFile() throws IOException {
try (PrintWriter writer = new PrintWriter(new FileWriter("testAdminData.txt"))){ try (PrintWriter writer = new PrintWriter(new FileWriter("testAdminData.txt"))){
writer.println("Thomas"); writer.println("Thomas");
@ -74,9 +74,9 @@ class AdminTest {
assertEquals(1, testAdmins.size()); assertEquals(1, testAdmins.size());
Admin admin = testAdmins.get(0); 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());
} }
} }

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

@ -139,8 +139,8 @@ class AdministrationTest {
Admin result = administration.findAdminById("A2001"); Admin result = administration.findAdminById("A2001");
assertNotNull(result, "Admin should be found after being added."); 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 @Test
@ -151,7 +151,7 @@ class AdministrationTest {
Admin result = administration.findAdminById("A2002"); Admin result = administration.findAdminById("A2002");
assertNotNull(result, "Admin should be found by ID."); 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 @Test
@ -167,7 +167,7 @@ class AdministrationTest {
// Now, the student should be found // Now, the student should be found
assertNotNull(administration.findStudentById("S1001")); assertNotNull(administration.findStudentById("S1001"));
assertEquals("Alice", administration.findStudentById("S1001").getName());
assertEquals("Alice", administration.findStudentById("S1001").getStudentName());
} }
@Test @Test
@ -205,13 +205,13 @@ class AdministrationTest {
assertNotNull(retrievedStudent); assertNotNull(retrievedStudent);
// Asserting that the retrieved student's name matches the expected name // 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 // 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 // Asserting that the retrieved student's role matches the expected role
assertEquals("Student", retrievedStudent.getRole());
assertEquals("Student", retrievedStudent.getStudentRole());
} }
/** /**

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

@ -30,7 +30,7 @@ class StudentTest {
private static final Student sampleStudent = new Student("Sebastian Reichard", "S1001", "Student"); private static final Student sampleStudent = new Student("Sebastian Reichard", "S1001", "Student");
@org.junit.jupiter.api.Test @org.junit.jupiter.api.Test
void writeToFile() throws IOException {
void testWriteToFile() throws IOException {
Student student = sampleStudent; Student student = sampleStudent;
// String filename = "testStudentData.txt"; // String filename = "testStudentData.txt";
@ -46,7 +46,7 @@ class StudentTest {
} }
@Test @Test
void readFromFile() throws IOException {
void testReadFromFile() throws IOException {
try (PrintWriter writer = new PrintWriter(new FileWriter("testStudentData.txt"))){ try (PrintWriter writer = new PrintWriter(new FileWriter("testStudentData.txt"))){
writer.println("Sebastian Reichard"); writer.println("Sebastian Reichard");
@ -61,9 +61,9 @@ class StudentTest {
assertEquals(1, testStudents.size()); assertEquals(1, testStudents.size());
Student admin = testStudents.get(0); 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)); // Files.delete(Path.of(filename));

Loading…
Cancel
Save