From 809c76e9ce40596e898d4a04c984d38820f9d57b Mon Sep 17 00:00:00 2001 From: Habiba Sorour Date: Tue, 11 Aug 2026 00:17:44 +0300 Subject: [PATCH] addedthe question --- source/ch6_definingclasses.ptx | 43 ++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/source/ch6_definingclasses.ptx b/source/ch6_definingclasses.ptx index 4375608..734fb2b 100644 --- a/source/ch6_definingclasses.ptx +++ b/source/ch6_definingclasses.ptx @@ -1073,6 +1073,49 @@ public int compareTo(Fraction other) { // compare this fraction with another fra + + +

+ Rearrange the blocks to create a Student class that implements Comparable<Student>. The class should feature a private double gpa field and a compareTo method that compares students based on their GPA. +

+
+ + + + public class Student implements Comparable<Student> { + private double gpa; + + + public class Student extends Comparable<Student> { + public double gpa; + + + + + public Student(double gpa) { + this.gpa = gpa; + } + + + + + public int compareTo(Student other) { + return Double.compare(this.gpa, other.gpa); + } + + + public boolean compareTo(Student other) { + return this.gpa - other.gpa; + } + + + + + } + + +
+