Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package BankAccounts;
- public class Account implements AccountTotalable {
- public class AccountTotalable {
- }
- protected int AccountNum;
- protected String AccountType;
- protected double Amount;
- protected double Balance;
- protected double FeeCharge;
- protected static int AccountID;
- protected int CounterByType = 0;
- protected int CounterByNumber = 0;
- /**
- * @param accountNum
- * @param accountType
- * @param balance
- * @param CounterByNumber
- * @param CounterByType
- */
- public Account(int accountNum, String accountType, double balance, int accountID) {
- super();
- this.AccountNum = accountNum;
- this.AccountType = accountType;
- this.Balance = balance;
- this.AccountID = AccountID;
- AccountID =++CounterByType;
- AccountID =++CounterByNumber;
- }
- public double getBalance()
- {
- return this.Balance;
- }
- public int getAccountNum()
- {
- return this.AccountNum ;
- }
- public int getTotalAccountByNum(int CounterByNumber)
- {
- return this.CounterByNumber;
- }
- public int setTotalAccountByNum(){
- return this.CounterByNumber ;
- }
- public int getTotalAccountByType(int CounterByType)
- {
- return this.CounterByType;
- }
- public int setTotalAccountByType(int CounterByType, int TotalAccountByType){
- return this.CounterByType ;
- }
- public void getAccountByType(Enum AccountByType,int AccountNum )
- {
- this.AccountNum = AccountNum ;
- }
- public boolean withDraw(double Amount)
- {
- if(Balance > 0 && Balance != 0){
- this.Balance = Balance - Amount;
- return true;
- }
- return false;
- }
- public double Balance(double Amount)
- {
- if(Balance > 0 && Balance != 0){
- Balance = Balance - Amount;}
- return this.Balance;
- }
- public void Deposit(double Amount){
- Balance = Balance + Amount;
- }
- public double getDeposit() {
- return this.Amount;
- }
- public double setDeposit(){
- return Amount;
- }
- public int AccountByType(int CounterByType)
- {
- return this.CounterByType += 1;
- }
- public int getAccountFee(int FeeCharge)
- {
- return FeeCharge;
- }
- public double setAccountFee(int AccountNum)
- {
- switch(AccountNum){
- case 10001:
- return this.FeeCharge = Balance * 0.05;
- case 20001:
- return this.FeeCharge = Balance * 0.0;
- case 30001:
- return this.FeeCharge = Balance * 0.02;
- case 40001:
- return this.FeeCharge = Balance * 0.01;
- }
- return this.FeeCharge;
- }
- public BankAccounts.AccountsByName.AccountByType getAccountByType(int AccountNum) {
- switch(this.AccountNum){
- case 10001:
- return BankAccounts.AccountsByName.AccountByType.REGULAR;
- case 20001:
- return BankAccounts.AccountsByName.AccountByType.TEENAGE;
- case 30001:
- return BankAccounts.AccountsByName.AccountByType.BUSSINESS;
- case 40001:
- return BankAccounts.AccountsByName.AccountByType.STUDENT;
- }
- return BankAccounts.AccountsByName.AccountByType.OTHER;
- }
- public double getBalance(double Balance) {
- return this.Balance = Balance - (Balance * FeeCharge);
- }
- public String toString()
- {
- return " Name: "+AccountType+
- " Number: "+AccountNum+
- " Balance: " +Balance+" Fees Charged: "+FeeCharge+
- " Deposit: " +Amount+
- " Counter By Number: "+CounterByNumber+
- " Counter By Type: "+CounterByType;
- }
- }
- package BankAccounts;
- public class Students extends Account implements AccountTotalable {
- protected int NumberPayments = 0;
- protected double SumofPayment = 0;
- protected double LoanAmount = 0;
- protected boolean HaveLoan = true;
- /**
- * @param accountNum
- * @param accountType
- * @param balance
- * @param numberPayments
- * @param loanAmount
- * @param SumofPayment
- * @param CounterByNumber
- * @param CounterByType
- */
- public Students(int accountNum, String accountType, double balance, int numberPayments, double loanAmount, int AccountID) {
- super(accountNum, accountType, balance, numberPayments);
- this.NumberPayments = numberPayments;
- this.LoanAmount = loanAmount;
- this.AccountID = AccountID;
- AccountID =++CounterByType;
- AccountID =++CounterByNumber;
- }
- public int getNumberPayments() {
- return NumberPayments;
- }
- public void setNumberPayments(int numberPayments) {
- NumberPayments = numberPayments;
- }
- public double getLoanAmount() {
- return LoanAmount;
- }
- public void setLoanAmount(double LoanAmount) {
- this.LoanAmount = LoanAmount;
- }
- public double getSumofPayment() {
- this.SumofPayment = LoanAmount / NumberPayments;
- return SumofPayment;
- }
- public void setSumofPayment(double SumofPayment) {
- this.SumofPayment = SumofPayment;
- }
- public int getAccountNum() {
- return AccountNum;
- }
- public void setAccountNumber(int AccountNum) {
- this.AccountNum = AccountNum;
- }
- public double getBalance(double Balance) {
- this.Balance = (LoanAmount + (LoanAmount * FeeCharge)) / NumberPayments;
- return this.Balance;
- }
- public void Deposit(double Amount){
- Balance = Balance + Amount;
- }
- public double getDeposit() {
- return this.Amount;
- }
- public double setDeposit(){
- return Amount;
- }
- public String toString()
- {
- return " Name: "+AccountType+
- " Number: "+AccountNum+
- " Balance: " +Balance+" Fees Charged: "+FeeCharge+
- " Deposit: " +Amount+
- " Counter By Number: "+CounterByNumber+
- " Counter By Type: "+CounterByType;
- }
- }
- package BankAccounts;
- public interface AccountTotalable {
- public default double getBalance(double Balance) {
- return Balance;
- }
- }
- package BankAccounts;
- public class AccountsByName extends Account implements AccountTotalable{
- public AccountsByName(String AccountByType, int AccountNum, double Balance, Enum AccountBytype) {
- super(AccountNum, AccountByType, Balance, AccountID);
- }
- public enum AccountByType {
- REGULAR("Regular", 10001),
- TEENAGE("Teenage", 20001),
- BUSSINESS("Bussiness", 30001),
- STUDENT("Student", 40001),
- OTHER("Other", 50001);
- protected final String Description;
- protected final int AccountNumber;
- AccountByType(String Description, int AccountNumber)
- {
- this.Description = Description;
- this.AccountNumber = AccountNumber;
- }
- }
- private int AccountNumber;
- public String getDescription()
- {
- return getDescription();
- }
- public int getaccountNumber()
- {
- return getaccountNumber();
- }
- public String getAccountsByType(int AccountNumber){
- this.setAccountNumber(AccountNumber);
- switch(AccountNumber){
- case 10001:
- this.setDescription("Regular");
- CounterByNumber += 1;
- CounterByType += 1;
- break;
- case 20001:
- this.setDescription("Teenage");
- CounterByNumber += 1;
- CounterByType += 1;
- break;
- case 30001:
- this.setDescription("Bussiness");
- CounterByNumber += 1;
- CounterByType += 1;
- break;
- case 40001:
- this.setDescription("Student");
- CounterByNumber += 1;
- CounterByType += 1;
- break;
- }
- return "Account Number is Not Defined!";
- }
- private String setDescription(String string) {
- // TODO Auto-generated method stub
- return getDescription();
- }
- protected int NumberOfPayments;
- protected double LoanSum;
- public int getAccountNumber() {
- return AccountNumber;
- }
- public void setAccountNumber(int AccountNumber) {
- this.AccountNumber = AccountNumber;
- }
- public int getNumberOfPayments() {
- return NumberOfPayments;
- }
- public void setNumberOfPayments(int NumberOfPayments) {
- this.NumberOfPayments = NumberOfPayments;
- }
- public double getLoanSum() {
- return LoanSum;
- }
- public void setLoanSum(double loanSum) {
- LoanSum = loanSum;
- }
- public String toString()
- {
- return "Account Holder Name: "+ AccountType+
- " Number of Payments: "+NumberOfPayments+
- " Loan Sum: "+LoanSum;
- }
- }
- package BankAccounts;
- public class BankAccountTester {
- public static void main(String[] args) {
- Account[] Cust1 = new Account[4];
- Cust1[0] = new Account(10001, "Foofo ", 11500, 1);
- Cust1[1] = new Students(40001, "Moomo ", 15000, 20, 20000, 2);
- Cust1[2] = new Account(20001, "Mousee ", 7000, 3);
- Cust1[3] = new Students(40001, "Seecee ", 12000, 10, 20000, 4);
- for (int i = 0; i < Cust1.length; i++) {
- if (Cust1[i] instanceof Account) {
- System.out.println(Cust1[i]);
- Cust1[i].withDraw(1000);
- Cust1[i].Deposit(5000);
- System.out.println(Cust1[i]);
- System.out.println("================================");
- int Actnum2 = Cust1[i].getAccountNum();
- System.out.println(Cust1[i].getAccountFee(Actnum2));
- System.out.println(Cust1[i].getAccountByType(Actnum2));
- System.out.println("Balance: " + (Cust1[i].getBalance()));
- } else if (Cust1[i] instanceof Students) {
- System.out.println(Cust1[i]);
- int Actnum = Cust1[i].getAccountNum();
- System.out.println(Cust1[i].getAccountFee(Actnum));
- System.out.println(Cust1[i].getAccountByType(Actnum));
- Cust1[i].getAccountFee(400);
- Cust1[i].withDraw(4000);
- System.out.println(Cust1[i]);
- Cust1[i].Deposit(250000);
- System.out.println(Cust1[i]);
- System.out.println("Balance: " + (Cust1[i].getBalance()));
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment