-
Notifications
You must be signed in to change notification settings - Fork 0
/
User.kt
96 lines (79 loc) · 2.12 KB
/
User.kt
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
fun main() {
// val user: User = User()
// user.email
val account = Account(12345,"Keshav",1000f)
// val account2 = Account(12345,"Keshav" )
// val account3 = Account(12345)
account.deposit(100f)
account.withDraw(150f)
account.withDraw(50f)
println("Account no = ${account.accNo} , name = ${account.name} , amount = ${account.amount}")
}
class User {
val name:String = ""
val mobile:Int = 0
val gender:String = ""
val email:String = ""
val bio:String = ""
fun checkEmail():Boolean{
return email.isNotEmpty()
}
}
class Account(var accNo:Int,var name:String,var amount:Float){ //1st way to write a primary constructors
//// 2nd way to write primary constructors
// var accNo:Int
// var name:String
// var amount:Float
// init {
// this.accNo=accNo
// this.name=name.capitalize()
// this.amount=amount + 10000
// }
// //Class Properties
// var accNo:Int = 0
// var name:String?=null
// var amount:Float=0f
//Constructor
/*
It is a function with same name as class name
It is used to construct or initialize the class
2 types :-
1.Primary Constructor - Only 1
2.Secondary Constructor - Multiple Secondary Constructors
*/
// //Secondary Constructors
// constructor(accNo: Int){
// this.accNo=accNo
// name="Default"
// amount=0f
// }
// constructor(accNo: Int,name: String){
// this.accNo=accNo
// this.name=name
// amount=0f
// }
// constructor(accNo: Int,name: String,amount: Float){
// this.accNo=accNo
// this.name=name
// this.amount=amount
// }
// fun Account(){
// //this point to the current receiver
// this.accNo=accNo
// this.name=name
// this.amount=amount
// }
//Member functions
fun deposit(money:Float){
amount += money;
println(amount)
}
fun withDraw(money: Float){
if(amount<money){
println("Insufficient balance")
}else{
amount-=money;
println(amount)
}
}
}