Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
/gradle/wrapper/gradle-wrapper.properties

# Ignore temp notes file
ignore.txt

##----------Android----------
*.apk
*.ap_
Expand Down
25 changes: 25 additions & 0 deletions src/Features/Calculator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
public class Calculator {

public double add(double a, double b) {
System.out.println("Add: a=" + a + ", b=" + b);
return a + b;
}

public double subtract(double a, double b) {
System.out.println("Subtract: a=" + a + ", b=" + b);
return a - b;
}

public double multiply(double a, double b) {
System.out.println("Multiply: a=" + a + ", b=" + b);
return a * b;
}

public double divide(double a, double b) {
if (b == 0.0) {
throw new IllegalArgumentException("Division by zero");
}
System.out.println("Divide: a=" + a + ", b=" + b);
return a / b;
}
}
46 changes: 46 additions & 0 deletions src/Features/Grade.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
public class Grade {

// Simple numeric -> letter grade
public String toLetter(double score) {
if (score < 0 || score > 100) {
throw new IllegalArgumentException("Score must be 0..100");
}
if (score >= 90) return "A";
if (score >= 80) return "B";
if (score >= 70) return "C";
if (score >= 60) return "D";
return "F";
}

// GPA points (typical 4.0 scale)
public double toGpaPoints(double score) {
String letter = toLetter(score);
switch (letter) {
case "A": return 4.0;
case "B": return 3.0;
case "C": return 2.0;
case "D": return 1.0;
default: return 0.0;
}
}

// Average of array
public double average(double[] scores) {
if (scores == null || scores.length == 0) {
throw new IllegalArgumentException("Scores required");
}
double sum = 0;
for (double s : scores) {
if (s < 0 || s > 100) {
throw new IllegalArgumentException("Score out of range: " + s);
}
sum += s;
}
return sum / scores.length;
}

// Average letter
public String averageLetter(double[] scores) {
return toLetter(average(scores));
}
}
80 changes: 80 additions & 0 deletions src/Features/Student.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
Loading