-
Notifications
You must be signed in to change notification settings - Fork 1
/
HoaDonTienNuoc.java
62 lines (56 loc) · 1.77 KB
/
HoaDonTienNuoc.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package NewNhanVien;
import java.util.*;
/**
*
* @author Administrator
*/
class KhachHang implements Comparable<KhachHang>{
private String id;
private String name;
private double oldIdx;
private double newIdx;
public KhachHang(int id, String name, double oldIdx, double newIdx) {
this.id = "KH" + String.format("%02d", id);
this.name = name;
this.oldIdx = oldIdx;
this.newIdx = newIdx;
}
private double getCost(){
double cost = this.newIdx - this.oldIdx;
if(cost <= 50)
return cost * 100 * 1.02;
else if(cost <= 100)
return (5000 + (cost - 50) * 150) * 1.03;
return (5000 + 7500 + (cost - 100) * 200) * 1.05;
}
@Override
public int compareTo(KhachHang b){
return -Double.compare(this.getCost(), b.getCost());
}
@Override
public String toString() {
return String.format("%s %s %.0f", this.id, this.name, this.getCost());
}
}
public class HoaDonTienNuoc {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
ArrayList<KhachHang> a = new ArrayList<>();
for(int i=1; i<=n; i++){
sc.nextLine();
String name = sc.nextLine();
double oi = sc.nextDouble();
double ni = sc.nextDouble();
a.add(new KhachHang(i, name, oi, ni));
}
Collections.sort(a);
for(KhachHang i : a){
System.out.println(i);
}
}
}