-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRide.java
More file actions
51 lines (45 loc) · 1.95 KB
/
Ride.java
File metadata and controls
51 lines (45 loc) · 1.95 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 Ride implements Order {
private Customer customer;
private String pickup;
private String destination;
private double jarak;
private String driver;
public Ride(Customer customer, String pickup, String destination, double jarak) {
this.customer = customer;
this.pickup = pickup;
this.destination = destination;
this.jarak = jarak;
this.driver = pilihDriver();
}
// Menampilkan daftar driver dan memilih satu secara acak
private String pilihDriver() {
String[] daftarDriver = { "Ahmad", "Arsyi", "Aksa", "Bintang", "Rijal" };
int index = ThreadLocalRandom.current().nextInt(daftarDriver.length);
String driverTerpilih = daftarDriver[index];
System.out.println("========================================");
System.out.println(" Driver terpilih: " + driverTerpilih);
return driverTerpilih;
}
public void process() {
System.out.println("========================================");
System.out.println("======= PEMESANAN RIDE ========");
System.out.println("========================================");
System.out.println("Nama Customer : " + customer.getName());
System.out.println("Driver : " + driver);
System.out.println("Dari : " + pickup);
System.out.println("Ke : " + destination);
System.out.println("Jarak : " + jarak + " km");
System.out.println("Total Biaya : Rp" + calculateCost());
System.out.println("");
System.out.println(customer.getName() + " Naik Ojek dari " + pickup + " ke " + destination);
System.out.println("========================================");
}
public double calculateCost() {
if (jarak <= 5) {
return jarak * 4000;
} else {
return (5 * 4000) + ((jarak - 5) * 5000);
}
}
}