-
Notifications
You must be signed in to change notification settings - Fork 0
/
impl.rs
43 lines (37 loc) · 934 Bytes
/
impl.rs
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
struct Pekerja{
id: u8,
nama: String,
umur: u8,
total_absen: u128
}
impl Pekerja{
fn profile(&self){
println!(
"id : {}, nama: {}, umur: {}, total-absen: {}",
self.id, self.nama, self.umur, self.total_absen
);
}
fn hitung_gaji(&self) -> u128{
let gaji_hari: u128 = 50000;
let hasil: u128 = gaji_hari * self.total_absen;
hasil // return
}
}
fn main(){
let pekerja1 = Pekerja {
id: 1,
nama: String::from("Adiyaksa"),
umur: 15,
total_absen: 30,
};
let pekerja2 = Pekerja {
id: 2,
nama: String::from("uyu"),
umur: 15,
total_absen: 128
};
pekerja1.profile();
pekerja2.profile();
println!("Gaji pekerja 1: {}", pekerja1.hitung_gaji());
println!("Gaji pekerja 2: {}", pekerja2.hitung_gaji());
}