-
Notifications
You must be signed in to change notification settings - Fork 0
/
Constructor.java
102 lines (77 loc) · 2.45 KB
/
Constructor.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
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
97
98
99
100
101
102
// Constructor.java
package com.company;
public class Constructor {
public static void main(String[] args) {
GrocMarket myAccount = new GrocMarket("Manish", "#1256", "98356", 100, "USA");
System.out.println(myAccount.getAccBal());
System.out.println(myAccount.getCustPhNo());
GrocMarket newAcc = new GrocMarket("NewCust", "#121212", "1212121");
System.out.println(newAcc.getCustName());
System.out.println(newAcc.getAccBal());
}
}
// GrocMarket.java
package com.company;
public class GrocMarket {
private String custName;
private String custID;
private String custPhNo;
private double accBal;
private String address;
private final double RECBaN = 100;
public GrocMarket(String custName, String custID, String custPhNo, double accBal, String address) {
this.custName = custName;
this.custID = custID;
this.custPhNo = custPhNo;
this.accBal = accBal;
this.address = address;
System.out.println("Constructor Called");
}
public GrocMarket(String custName, String custID, String custPhNo) {
this(custName, custID, custPhNo, 200, "Sydney");
}
public String getCustName() {
return custName;
}
public void setCustName(String custName) {
this.custName = custName;
}
public String getCustID() {
return custID;
}
public void setCustID(String custID) {
this.custID = custID;
}
public String getCustPhNo() {
return custPhNo;
}
public void setCustPhNo(String custPhNo) {
this.custPhNo = custPhNo;
}
public double getAccBal() {
return accBal;
}
public void setAccBal(double accBal) {
this.accBal = accBal;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public void Shop(double amount) {
if (accBal >= amount) {
double remBal = accBal - amount;
System.out.println("Thanks for Shopping. Your balance amount is: " + remBal);
accBal = remBal;
} else {
double lowAmount = amount - RECBaN;
System.out.println("Insufficient Amount: Add more money: " + lowAmount);
}
}
public void rechargeAcc(double recharge) {
accBal += recharge;
System.out.println("Thanks for recharging. Your new balance is: " + accBal);
}
}