-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCreditCard.java
More file actions
executable file
·57 lines (47 loc) · 1.08 KB
/
Copy pathCreditCard.java
File metadata and controls
executable file
·57 lines (47 loc) · 1.08 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
53
54
55
56
57
public class CreditCard
{
private int expiryMonth;
private int expiryYear;
private String firstName;
private String lastName;
private String ccNumber;
private final String NOW = "02/11";
public String getExpiryDate()
{
return (expiryMonth + "/" + expiryYear);
}
public String getName()
{
return (firstName + " " + lastName);
}
public String getCcNumber()
{
return ccNumber;
}
public boolean isExpired()
{
int month = Integer.parseInt(NOW.substring(0,1));
int year = Integer.parseInt(NOW.substring(3,4));
if (expiryMonth < month && expiryYear < year) return false;
else return true;
}
public String toString()
{
String ccNum = getCcNumber();
String name = getName();
String ExpDate = getExpiryDate();
String s = ccNum + '\n' + name + '\n' + ExpDate + '\n';
if (isExpired())
s += "Expired";
else s += "Not expired";
return s;
}
public CreditCard(int ExpMonth, int ExpYear, String fName, String lName, String cNum)
{
expiryMonth = ExpMonth;
expiryYear = ExpYear;
firstName = fName;
lastName = lName;
ccNumber = cNum;
}
}