-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFootballPlayer.java
More file actions
53 lines (46 loc) · 1.69 KB
/
FootballPlayer.java
File metadata and controls
53 lines (46 loc) · 1.69 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
package huongdoituong;
import java.util.ArrayList;
class FootballPlayer {
private String name;
private int age;
private String add;
private double height;
private double weight;
private long salary;
public FootballPlayer() {}
public FootballPlayer(String name, int age, String add, double height, double weight, long salary) {
this.name = name;
this.age = age;
this.add = add;
this.height = height;
this.weight = weight;
this.salary = salary;
}
public long getSalary() {
return salary;
}
public int getAge() {
return age;
}
public void display() {
System.out.println("Name: " + name + ", Age: " + age + ", Address: " + add + ", Height: " + height + ", Weight: " + weight + ", Salary: " + salary);
}
public static ArrayList<FootballPlayer> sortSalary(ArrayList<FootballPlayer> v) {
int n = v.size();
// v là tham số chứa danh sách cần sắp xếp
for (int i = 0; i < n-1; i++) {
for (int j = 0; j < n-i-1; j++) {
if (v.get(j).getSalary() > v.get(j+1).getSalary()) {
// So sánh lương của hai cầu thủ liền kề
FootballPlayer temp = v.get(j);
// Lưu cầu thủ ở vị trí j vào biến tạm temp
v.set(j, v.get(j+1));
//Đặt cầu thủ ở vị trí j+1 vào vị trí j
v.set(j+1, temp);
//Đặt cầu thủ từ biến tạm temp vào vị trí j+1
}
}
}
return v;
}
}