Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Consider the following classes: public class Ch10_Student implements Comparable{ private int id; private int gpa; public Ch10_Student(int id, int gpa) { this.id = id; this.gpa

Consider the following classes:

public class Ch10_Student implements Comparable{

private int id; private int gpa;

public Ch10_Student(int id, int gpa)

{ this.id = id; this.gpa = gpa; }

public int getId(){return id;} public int getGpa(){return gpa;}

public int compareTo(Ch10_Student other){ return this.id - other.id; } }

import java.util.*;

public class Ch10_Student_Test{

public static void main(String[] args){

ArrayList students = new ArrayList();

students.add(new Ch10_Student(8, 4));

students.add(new Ch10_Student(7, 2));

students.add(new Ch10_Student(5, 3));

Collections.sort(students);

System.out.println(students.get(0).getGpa());

} }

I just have a question about this code; do I need to write a separate code for the comparable Interface or no, and if yes, what will be the code in the comparable Interface?

Thanks.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Define job pricing. What is the purpose of job pricing?

Answered: 1 week ago

Question

What are some companywide pay plans? Briefly discuss each.

Answered: 1 week ago