-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSend.java
More file actions
51 lines (44 loc) · 1.94 KB
/
Send.java
File metadata and controls
51 lines (44 loc) · 1.94 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
import java.util.concurrent.ThreadLocalRandom;
public class Send implements Order {
private Customer customer;
private String courir;
private String destination;
private String item;
private double weight; // berat dalam kg
public Send(Customer customer, String destination, String item, double weight) {
this.customer = customer;
this.courir = pilihCourir();
this.destination = destination;
this.item = item;
this.weight = weight;
}
private String pilihCourir() {
String[] daftarCourir = { "Ahmad (JNE)", "Arsyi (JNT)", "Aksa (SPX)", "Bintang (Wahana)", "Rijal(SiCepat)" };
int index = ThreadLocalRandom.current().nextInt(daftarCourir.length);
String courirTerpilih = daftarCourir[index];
System.out.println("========================================");
System.out.println(" Driver terpilih: " + courirTerpilih);
return courirTerpilih;
}
public void process() {
System.out.println("========================================");
System.out.println("======= PEMESANAN SEND ========");
System.out.println("========================================");
System.out.println("Nama Customer : " + customer.getName());
System.out.println("Kurir : " + courir);
System.out.println("Barang : " + item);
System.out.println("Ke : " + destination);
System.out.println("Berat : " + weight + " kg");
System.out.println("Total Biaya : Rp" + calculateCost());
System.out.println("");
System.out.println(customer.getName() + " mengirim " + item + " ke " + destination);
System.out.println("========================================");
}
public double calculateCost() {
if (weight <= 5) {
return weight * 4000;
} else {
return (5 * 4000) + ((weight - 5) * 5000);
}
}
}