-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJ05012_TinhTien.java
46 lines (40 loc) · 1.37 KB
/
J05012_TinhTien.java
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
//B21DCCN441
import java.io.*;
import java.util.*;
import java.math.*;
class matHang {
public String id, name;
public long soLuong, donGia, chietKhau, tongTien;
public matHang(String Id, String Name, long Soluong, long Dongia, long Chietkhau) {
this.id = Id;
this.name = Name;
this.soLuong = Soluong;
this.donGia = Dongia;
this.chietKhau = Chietkhau;
this.tongTien = this.soLuong * this.donGia - this.chietKhau;
}
@Override
public String toString() {
return this.id + " " + this.name + " " + this.soLuong + " " + this.donGia + " " + this.chietKhau + " " + this.tongTien;
}
}
public class J05012_TinhTien {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
ArrayList<matHang> a = new ArrayList<>();
for (int i = 1; i <= n; i++) {
sc.nextLine();
a.add(new matHang(sc.nextLine(), sc.nextLine(), sc.nextLong(), sc.nextLong(), sc.nextLong()));
}
Collections.sort(a, new Comparator<matHang>() {
@Override
public int compare(matHang t, matHang t1) {
return t.tongTien > t1.tongTien ? -1 : 1;
}
});
for (matHang mh : a) {
System.out.println(mh);
}
}
}