Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- teenage.class
- =================
- package ClsBank;
- public class Teenage extends Account {
- public Teenage(String accountName, String id, int age) {
- super(accountName, id, age);
- Account.teenageAccountCounter+=1;
- this.accountNumber=Integer.parseInt(Account.TEENAGE_PERFIX+Account.teenageAccountCounter);
- }
- }
- account.class
- ====================
- package ClsBank;
- public abstract class Account implements AccountAble {
- // Static Variable
- protected static int studentAccountCounter = 0;
- protected static int bussniessAccountCounter = 0;
- protected static int regularAccountCounter = 0;
- protected static int teenageAccountCounter = 0;
- final protected static String TEENAGE_PERFIX="4";
- // normal variable
- protected int accountNumber = 0;
- protected int age = 0;
- protected String accountType = ""; // st,bu,re,te
- protected String accountName = "";
- protected String id;
- protected double balance=0;
- protected int fee=-1;
- protected boolean isClosed=false;
- public Account(String accountName, String id, int age) {
- this.accountName = accountName;
- this.id = id;
- this.age = age;
- this.balance=0;
- }
- @Override
- public int getTotalAccounts() {
- return (this.studentAccountCounter + this.bussniessAccountCounter
- + this.regularAccountCounter + this.teenageAccountCounter);
- }
- @Override
- public int getTotalAccountByType() {
- // st,bu,re,te
- int returnValue = 0;
- String myAccount = this.accountNumber+"";
- switch (myAccount.charAt(0))
- {
- case '1':
- returnValue=this.studentAccountCounter;
- break;
- case '2':
- returnValue=this.bussniessAccountCounter;
- break;
- case '3':
- returnValue=this.regularAccountCounter;
- break;
- case '4':
- returnValue=this.teenageAccountCounter;
- break;
- default:
- returnValue=0;
- }
- return returnValue;
- }
- @Override
- public double getBalance() {
- return this.balance;
- }
- @Override
- public void setAccountFee(int fee) {
- this.fee=fee;
- }
- @Override
- public double getAccountFee() {
- // TODO Auto-generated method stub
- return this.fee;
- }
- @Override
- public void withDraw(double amount) throws Exception {
- checkConditions(amount);
- double amountFee=amount*(1+this.fee/100);
- if (amountFee>this.balance) throw new Exception("Insffiecent funds");
- this.balance-=amountFee;
- }
- @Override
- public void deposit(double amount) throws Exception {
- checkConditions(amount);
- double amountFee=amount*(1-this.fee/100);
- this.balance+=amountFee;
- }
- private void checkConditions(double amount) throws Exception
- {
- if (this.fee<0) throw new Exception("Please set fee to the account");
- if (amount<0) throw new Exception("Number must be positive"); //Eti Alon
- if (amount>10000) throw new Exception("Limited to 9,999Nis only");
- if (this.isClosed) throw new Exception("Account is closed");
- }
- @Override
- public int getAccountNumber() {
- return this.accountNumber;
- }
- @Override
- public int getAge() {
- return this.age;
- }
- @Override
- public void closeAccount() throws Exception {
- if (this.balance<0) throw new Exception("the account in overdraft");
- if (this.balance>0) throw new Exception("Withdraw all the money");
- //close the account
- this.isClosed=true;
- }
- }
- accountable.interface
- ==========================
- package ClsBank;
- public interface AccountAble {
- int getTotalAccounts(); //get total of accounts in bank
- int getTotalAccountByType ();
- double getBalance();
- void withDraw(double amount) throws Exception;
- void setAccountFee(int fee);
- double getAccountFee();
- void deposit(double amount) throws Exception;
- int getAccountNumber();
- int getAge();
- void closeAccount() throws Exception;
- }
Add Comment
Please, Sign In to add comment