-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathStudents.java
More file actions
57 lines (52 loc) · 1.29 KB
/
Students.java
File metadata and controls
57 lines (52 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package basic;
import java.util.Scanner;
public class Students implements Comparable<Students> {
private String name;
private double average;
//get, set
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getAverage() {
return average;
}
public void setAverage(double average) {
this.average = average;
}
//default constructor
public Students() {
this.name="";
this.average=0.0;
}
//parameterized constructor
public Students(String name, double average) {
this.name=name;
this.average=average;
}
public Students(Students s) {
this.name = s.name;
this.average=s.average;
}
public void input() {
Scanner sc=new Scanner(System.in);
System.out.println("Enter name");
this.name = sc.nextLine();
System.out.println("Enter average");
this.average=Double.parseDouble(sc.nextLine());
}
public void output() {
System.out.println("Student has"+this.getName()+" and average ="+this.getAverage());
}
public int compareTo(Students A,Students B) {
return (int)(A.average - B.average);
}
@Override
public int compareTo(Students other) {
// TODO Auto-generated method stub
Students student = other;
return (int)(this.average-other.average);
}
}