From ea7fa5a536a0f2e8f06ec5e95fc4f421d40e6790 Mon Sep 17 00:00:00 2001 From: Adi-Sin101 Date: Thu, 21 Aug 2025 18:59:28 +0600 Subject: [PATCH 1/2] Add Student class with constructors, getters, setters --- src/Features/Student.java | 80 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 src/Features/Student.java diff --git a/src/Features/Student.java b/src/Features/Student.java new file mode 100644 index 000000000000..6fee9bf31ffd --- /dev/null +++ b/src/Features/Student.java @@ -0,0 +1,80 @@ +public class Student { + + private String id; + private String name; + private String email; + private String department; + private double gpa; + + // No-arg constructor + public Student() { + } + + // Parameterized constructor + public Student(String id, String name, String email, String department, double gpa) { + this.id = id; + this.name = name; + this.email = email; + this.department = department; + this.gpa = gpa; + } + + // Copy constructor + public Student(Student other) { + if (other != null) { + this.id = other.id; + this.name = other.name; + this.email = other.email; + this.department = other.department; + this.gpa = other.gpa; + } + } + + // Getters + public String getId() { return id; } + public String getName() { return name; } + public String getEmail() { return email; } + public String getDepartment() { return department; } + public double getGpa() { return gpa; } + + // Setters + public void setId(String id) { this.id = id; } + public void setName(String name) { this.name = name; } + public void setEmail(String email) { this.email = email; } + public void setDepartment(String department) { this.department = department; } + public void setGpa(double gpa) { + if (gpa < 0.0) gpa = 0.0; + if (gpa > 4.0) gpa = 4.0; + this.gpa = gpa; + } + + // Convenience builder-style methods (optional chaining) + public Student withId(String id) { setId(id); return this; } + public Student withName(String name) { setName(name); return this; } + public Student withEmail(String email) { setEmail(email); return this; } + public Student withDepartment(String department) { setDepartment(department); return this; } + public Student withGpa(double gpa) { setGpa(gpa); return this; } + + @Override + public String toString() { + return "Student{id='" + id + '\'' + + ", name='" + name + '\'' + + ", email='" + email + '\'' + + ", department='" + department + '\'' + + ", gpa=" + gpa + + '}'; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof Student)) return false; + Student s = (Student) o; + return (id != null && id.equals(s.id)); + } + + @Override + public int hashCode() { + return id == null ? 0 : id.hashCode(); + } +} From d25a7d2c315c7085c1dd92a431b3642750944ed7 Mon Sep 17 00:00:00 2001 From: Adi-Sin101 Date: Thu, 21 Aug 2025 19:02:39 +0600 Subject: [PATCH 2/2] Add Calculator class with basic arithmetic methods --- src/Features/Calculator.java | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/Features/Calculator.java diff --git a/src/Features/Calculator.java b/src/Features/Calculator.java new file mode 100644 index 000000000000..63b13e07548d --- /dev/null +++ b/src/Features/Calculator.java @@ -0,0 +1,21 @@ +public class Calculator { + + public double add(double a, double b) { + return a + b; + } + + public double subtract(double a, double b) { + return a - b; + } + + public double multiply(double a, double b) { + return a * b; + } + + public double divide(double a, double b) { + if (b == 0.0) { + throw new IllegalArgumentException("Division by zero"); + } + return a / b; + } +}