forked from Denisolt/CSCI-160
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreditCard.java
More file actions
52 lines (47 loc) · 1.12 KB
/
CreditCard.java
File metadata and controls
52 lines (47 loc) · 1.12 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
52
//Denisolt Shakhbulatov
public class CreditCard
{
private Money balance;
private Money creditLimit;
private Person owner;
public CreditCard(Person newCardHolder, Money limit)
{
owner = newCardHolder;
creditLimit = limit;
balance = new Money(0.0);
}
public Money getBalance()
{
return balance;
}
public Money getCreditLimit()
{
return creditLimit;
}
public String getPersonals()
{
return owner.toString();
}
public void charge(Money amount)
{ balance = amount.add(balance);
if(balance.compareTo(creditLimit)==1)
{
System.out.println("Exceeds credit limit");
balance = balance.subtract(amount);
}
else
{
System.out.println("Charge: " + amount);
}
}
public void payment(Money amount)
{
if(amount.compareTo(balance)==1)
System.out.println("Not enough money on the card" );
else
{
System.out.println("Payment: " + amount);
balance = balance.subtract(amount);
}
}
}