-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAccount.java
More file actions
61 lines (56 loc) · 1.56 KB
/
Account.java
File metadata and controls
61 lines (56 loc) · 1.56 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
58
59
60
61
package bankaccountapp;
import java.util.Random;
public abstract class Account implements IBaseRate{
private String name;
private String sSN;
protected String accountNumber;
private static int index=10000;
private double balance;
protected double rate;
public Account(String name,String sSN,double initdeposit){
this.name=name;
this.sSN=sSN;
balance=initdeposit;
index++;
this.accountNumber=setAccountNumber();
setRate();
}
public abstract void setRate() ;
private String setAccountNumber(){
String lasttwoOfSSN=sSN.substring(sSN.length()-2, sSN.length());
int uniqueID=index;
int randomNumber=(int)(Math.random()*Math.pow(10, 3));
return lasttwoOfSSN+uniqueID+randomNumber;
}
public void compound(){
double accruedInterest=balance * (rate/100);
balance= balance+ accruedInterest;
System.out.println("Accrued interest: $"+accruedInterest);
printBalance();
}
public void Deposit(double amount){
balance=balance+amount;
System.out.println("Depositing $"+ amount);
printBalance();
}
public void withdraw(double amount){
balance=balance-amount;
System.out.println("withdrawing $"+amount);
printBalance();
}
public void transfer(String towhere,double amount){
balance=balance-amount;
System.out.println("Transfering $"+amount+" to "+towhere);
printBalance();
}
public void printBalance(){
System.out.println("your balance is now: $"+ balance);
}
public void showInfo(){
System.out.println(
"Name: "+ name
+"\nAccount Number: "+ accountNumber
+"\nBalance: "+balance
);
}
}