Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Tester;
- import bank.Account1;
- import bank.Bussniess;
- import bank.Student;
- import bank.Teenage;
- import bank.ageExcepptions;
- import bank.exceptionsAccount;
- import bank.Account;
- import java.util.Date;
- import java.util.InputMismatchException;
- import java.util.Scanner;
- import bank.regular;
- import bank.loanable;
- public class TestNewAccount {
- public static void main(String[] args) {
- Scanner in=new Scanner(System.in);
- try {
- Account1[] Account= new Account1[7];
- Account[0]=new Student("ahmad", 1236554, 29);
- Account[1]=new Student("zahra", 1569582,30);
- Account[2]=new Bussniess("foad", 1245423,19);
- Account[3]=new regular("rami", 2540063, 18);
- Account[4]=new Student("rana", 3644263,30);
- Account[5]=new Student("RON", 3114263,25);
- Account[6]=new Bussniess("JUN", 9814263,90);
- //show total accounts , show total bussniess count & student
- //---------------------------------------------------------------------------
- System.out.printf("Total Accounts is %s \n",((Account)Account[0]).getCount());
- System.out.println(((Bussniess) Account[2]).getBussniessCount()+(" of them is Bussniess Accounts "));
- System.out.println(((Student) Account[1]).getStudentCount()+(" of them is Student Accounts "));
- //----------------------------------------------------------------------------
- //-----------------------------------------------------------------------------
- ((Account)Account[6]).setFee(0.005); // personal fee
- ((Account)Account[6]).setBalance(2000); // set balance
- ((Account)Account[6]).setLimit(3000); // personal framework
- System.out.println(Account[6].withDraw(3000)); // with draw
- System.out.println(Account[6].toString()); //print all details of account 6
- //------------------------------------------------------------------------------
- //------------------------------------------------------------------------------
- System.out.println((((Student)Account[1]).toString()));// Student get a loan that equal to 20000
- System.out.println( ((Student)Account[1]).getLoan(20000, 12));//
- System.out.println( ((Student)Account[1]).isThereIsLoan());
- System.out.println(((Student)Account[1]).deposit(20000));
- ((Student)Account[1]).closeLoan(); //try to close loan
- ((Student)Account[1]).closeAccount(); //try to close account
- //-------------------------------------------------------------------------------
- //-------------------------------------------------------------------------------
- System.out.println(((Student)Account[1]).loanReturnByMonth()); // check value of loan return by month
- System.out.println("Enter loan value you want and payment");
- System.out.println(((Student)Account[0]).getLoan(in.nextDouble(), in.nextInt()));// try to get a new loan
- //--------------------------------------------------------------------------------
- }
- catch(InputMismatchException e){
- System.out.println(e.getMessage());
- }
- catch(ArithmeticException e){
- System.out.println(e.getMessage());
- }
- catch(Exception e){
- System.out.println(e.getMessage());
- }
- }
- }
- ================================================================================
- package bank;
- public class Account implements Account1 {
- //-----------------------------------------------------------------------------
- protected int PersonalLimit=0; //account framework
- protected String typeOfaccount;
- protected String name;
- protected int id;
- protected double balanc=0;
- protected static int count=0;
- protected static int studentCount=0;
- protected static int bussniessCount=0;
- protected static int regularCount=0;
- protected static int teenageCount=0;
- protected static int soldierCount=0;
- protected static double fee=0.00;
- protected int accountNumber=0;
- protected int age=0;
- protected int limit=0; // Account Framework
- protected int loan=0; //General Loan
- //-----------------------------------------------------------------------------
- public Account(String name, int id, int age) throws exceptionsAccount {
- super();
- this.name = name;
- this.id = id;
- this.count = count+1;
- this. accountNumber= this.id;
- this.age=age;
- if (this.id<100000000 && this.id>999999){
- this.id=id;
- }
- else idException.idException();
- }
- public int getPersonalLimit() {
- return PersonalLimit;
- }
- public void setPersonalLimit(int personalLimit) {
- this.limit = personalLimit;
- }
- public String getTypeOfaccount() {
- return typeOfaccount;
- }
- public void setTypeOfaccount(String typeOfaccount) {
- this.typeOfaccount = typeOfaccount;
- }
- public static int getBussniessCount() {
- return bussniessCount;
- }
- public static int getStudentCount() {
- return studentCount;
- }
- public static int getRegularCount() {
- return regularCount;
- }
- public static int getTeenageCount() {
- return teenageCount;
- }
- @Override
- public int getTotalAccount() {
- // TODO Auto-generated method stub
- return 0;
- }
- public void setBalance(double balanc){
- if (balanc>0){
- this.balanc=balanc;
- }
- else {
- try{
- balancException.balancException();
- }
- catch(Exception e){
- System.out.println(e.getMessage());
- }
- }
- }
- @Override
- public double getBalanc() {
- return this.balanc;
- }
- @Override
- public boolean withDraw(double amount) throws exceptionsAccount {
- double amountFee=amount*(1+this.fee);
- if (this.balanc>amountFee)
- {
- this.balanc-=amountFee;
- return true;
- }
- else if(this.balanc<amountFee && amountFee <(this.balanc+this.limit))
- {
- this.balanc-=amountFee;
- return true;
- }
- else {
- try {
- withDrawException.withDrawException(); }
- catch (Exception e) {
- System.out.println("you can't with draw this amount:" +" '"
- + amountFee +"' "+ e.getMessage()+(this.balanc+this.limit)+" NIS");
- }
- return false;
- }
- }
- public double getAccountFee() {
- return this.fee;
- }
- @Override
- public String deposit(double amount) {
- String msg = null;
- if(amount>0){
- msg="your balnc now is : " + this.balanc+amount;
- return msg ;
- }
- else
- try {
- depositException.depositException();}
- catch (exceptionsAccount e)
- {
- msg= "your balnc now is : " +" '" + this.balanc +"' "+ " "+ e.getMessage();
- }
- return msg;
- }
- public static double getFee() {
- return fee;
- }
- public static void setFee(double fee) {
- Account.fee = fee;
- }
- @Override
- public int getAccountNumber() {
- return this.accountNumber;
- }
- @Override
- public int getAge() {
- return this.age;
- }
- public int getCount() {
- return count;
- }
- @Override
- public int getTotalAccountByType(String Type) {
- // TODO Auto-generated method stub
- if(this instanceof Student){
- }
- if ( Type =="Teenage")
- {
- return teenageCount;
- }
- if (Type=="Bussniess")
- {
- return bussniessCount;
- }
- if (Type=="Student")
- {
- return studentCount;
- }
- if (Type=="Student")
- {
- return studentCount;
- }
- //if (Type=="regular")
- {
- return regularCount;
- }
- }
- public int getLimit() {
- return limit;
- }
- public void setLimit(int limit) {
- this.limit = limit;
- }
- @Override
- public String toString() {
- return "Account [name=" + name + ", id=" + id +
- " accountNumber=" + accountNumber +
- " typeOfaccount=" + getTypeOfaccount()
- + " balanc= "+ balanc + " accountNumber=" + accountNumber+"]";
- }
- @Override
- public void setAccountFee(int fee) {
- this.fee=fee;
- }
- @Override
- public void closeAccount() throws exceptionsAccount {
- if(this.balanc==0 && this.loan==0){
- System.out.println("your account is closed");
- }
- else
- closeAccountException.closeAccountException();
- }
- }
- ====================================================================================================
- package bank;
- public interface Account1 {
- int getTotalAccount();
- int getTotalAccountByType(String Type);
- double getBalanc();
- boolean withDraw(double amount) throws Exception;
- void setAccountFee(int fee);
- double getAccountFee();
- String deposit(double amount);
- int getAccountNumber() throws Exception;
- int getAge();
- int getCount();
- void closeAccount() throws exceptionsAccount;
- }
- ==============================================================================================
- package bank;
- public class ageExcepptions extends exceptionsAccount {
- public ageExcepptions(){
- super("to open account age must be more than 15 year old" );
- }
- public static void ageExcepptionsRegular()throws exceptionsAccount{
- throw new exceptionsAccount ("To Create Regular account or Bussniess account or Student account, age"
- + " must be more than 18 Try"
- + " to Create another type"
- + " account");
- }
- public static void ageExcepptionsTeenage()throws exceptionsAccount{
- throw new exceptionsAccount ("To Create Teenage account age"
- + "must be between 16-18 Try"
- + " to Create another type"
- + "of account");
- }
- public static void ageExcepptionsStudent()throws exceptionsAccount{
- throw new exceptionsAccount ("To Create Student account, age"
- + " must be more than 18, Try"
- + " to Create another type"
- + " account");
- }
- public static void ageExcepptionsAccount()throws exceptionsAccount{
- throw new exceptionsAccount ("To Create Account, age"
- + " must be more than 16 ");
- }
- public static void ageExcepptionsBussniess()throws exceptionsAccount{
- throw new exceptionsAccount ("To Create Bussniess account, age"
- + "must be more than 18 Try"
- + " to Create another type"
- + " account");
- }
- public static void ageExcepptionsSoldier()throws exceptionsAccount{
- throw new exceptionsAccount ("To Create Soldier account, age"
- + "must be more than 18 Try"
- + " to Create another type"
- + " account");
- }
- }
- ==========================================================================================
- package bank;
- public class attemptOpenNewLoan extends exceptionsAccount {
- public attemptOpenNewLoan(){
- super("failed becasue your have another loan" );
- }
- }
- =============================================================================================
- package bank;
- public class balancException extends exceptionsAccount {
- public balancException(String msg){
- super(msg);
- }
- public static void balancException() throws Exception{
- // TODO Auto-generated method stub
- throw new Exception ("balanc must be more than 0 ");
- }
- }
- ===========================================================================================
- package bank;
- public class Bussniess extends loanFunctionOnAble{
- public Bussniess(String name, int id, int age) throws exceptionsAccount {
- super(name, id, age);
- // TODO Auto-generated constructor stub
- bussniessCount+=1;
- this.loanPaymentLeft=0;
- this.paymentValue=0.00;
- this.loan=0;
- this.payment=0;
- this.limit=10000;
- fee=0.002;
- this.typeOfaccount="Bussniess";
- this.accountNumber=Integer.parseInt("2" + id);
- this.age=age;
- if(this.age>18){
- this.age=age;
- }
- else {
- ageExcepptions.ageExcepptionsBussniess();
- }
- }
- }
- =======================================================================================
- package bank;
- public class closeAccountException extends exceptionsAccount {
- public closeAccountException (String msg){
- super(msg);
- }
- public static void closeAccountException() throws exceptionsAccount{
- throw new exceptionsAccount ("you must close the loan and the minus ");
- }
- }
- ==================================================================================
- package bank;
- public class depositException extends exceptionsAccount {
- public depositException(String msg){
- super(msg);
- }
- public static void depositException() throws exceptionsAccount{
- throw new exceptionsAccount("Enter a possible values ");
- }
- }
- ================================================================================
- package bank;
- public class ErrorKeyBoardUsing extends exceptionsAccount {
- public ErrorKeyBoardUsing(){
- super(" recheck what you have written ");
- }
- }
- =================================================================================
- package bank;
- public class exceptionsAccount extends Exception{
- public exceptionsAccount(String msg){
- super(msg);
- }
- public exceptionsAccount(){
- super("return to your Account details there is exception");
- }
- }
- ================================================================================
- package bank;
- public class getLoanException extends exceptionsAccount {
- public getLoanException(){
- super("cliant can't take tow loan" );
- }
- }
- ===============================================================================
- package bank;
- public class idException extends exceptionsAccount{
- public idException (String msg){
- super(msg);
- }
- public static void idException() throws exceptionsAccount{
- throw new exceptionsAccount ("Id must be between 7-9 digit ");
- }
- }
- ==============================================================================
- package bank;
- public interface loanable {
- boolean isThereIsLoan(); // function that using to Check if there is a loan in Student Account
- boolean getLoan(double loan,int payment); //Open loan true only if customer don't have loan
- void closeLoan(); //function that using to closing each loan payments left or part of them
- String loanReturnByMonth(); // function that using to show loan details (loan value now, payment value left, payments)
- int getLoanPaymentLeft();// function that using to get loan payment left
- }
- ==========================================================================================
- package bank;
- import java.util.InputMismatchException;
- public class loanFunctionOnAble extends Account implements loanable {
- //------------------------------------------------------------
- protected double loan;
- protected int payment;
- protected int loanPaymentLeft;//save how many payments left
- protected double paymentValue;
- //-----------------------------------------------------------
- public loanFunctionOnAble(String name, int id, int age) throws exceptionsAccount {
- super(name, id, age);
- // TODO Auto-generated constructor stub
- }
- public void setPayment(int payment) {
- this.payment = payment;
- }
- @Override
- public void closeLoan() {
- if (this.balanc<=this.loan){
- try{
- this.loan=this.balanc-this.loan;
- this.balanc-=this.loan;
- System.out.println("client must paying "+Math.abs(this.loan)+" NIS to close the loan");
- }
- catch(InputMismatchException e){
- System.out.println(e.getMessage());
- }
- catch(ArithmeticException e){
- System.out.println(e.getMessage());
- }
- }
- else{
- try {
- this.loan=this.balanc-this.loan;
- this.balanc-=this.loan;
- System.out.println("your loan is: " + Math.abs(this.loan));
- }
- catch(InputMismatchException e){
- System.out.println(e.getMessage());
- }
- catch(ArithmeticException e){
- System.out.println(e.getMessage());
- }
- }
- }
- @Override
- public int getLoanPaymentLeft() {
- // TODO Auto-generated method stub
- try{
- loanPaymentLeft=(int) (Math.abs((this.loan)/this.paymentValue));
- }
- catch(InputMismatchException e){
- System.out.println(e.getMessage());
- }
- catch(ArithmeticException e){
- System.out.println(e.getMessage());
- }
- return loanPaymentLeft;
- }
- public String loanReturnByMonth() {
- return ("Account Number:"+ this.accountNumber +
- ", loan return by month is: "+
- + paymentValue +
- " loan payment left is: "+ getLoanPaymentLeft() +
- " , loan left is:"+ Math.abs(this.loan));
- }
- @Override
- public boolean isThereIsLoan() {
- // TODO Auto-generated method stub
- if (this.loan>0){
- return true;
- }
- else
- {
- return false;
- }
- // boolean answer=(loan>0? true: false);
- // return answer;
- }
- @Override
- public boolean getLoan(double loan, int payment) {
- // TODO Auto-generated method stub
- isThereIsLoan();
- boolean answer;
- if( isThereIsLoan()==true || loan>25000){
- answer= false;
- }
- else{
- this.loan=loan;
- this.payment=payment;
- answer= true;
- try{
- this.paymentValue=(this.loan/this.payment);
- }
- catch(InputMismatchException e){
- System.out.println(e.getMessage());
- }
- catch(ArithmeticException e){
- System.out.println(e.getMessage());
- }
- }
- return answer;
- }
- }
- ===========================================================================
- package bank;
- public class regular extends Account {
- public regular(String name, int id, int age) throws exceptionsAccount {
- super(name, id, age);
- regularCount+=1;
- this.typeOfaccount="regular";
- fee=0.005;
- this.limit=3000;
- this.accountNumber=Integer.parseInt("1" + id);
- if(age>18){
- this.age=age;
- }
- else if(age<18) try {
- ageExcepptions.ageExcepptionsRegular();
- }
- catch (exceptionsAccount e) {
- System.out.println(e.getMessage());
- }
- }
- }
- =========================================================================
- package bank;
- public class Soldier extends Account {
- public Soldier(String name, int id, int age) throws exceptionsAccount {
- super(name, id, age);
- this.soldierCount+=1;
- this.age=age;
- fee=0.001;
- this.typeOfaccount="Soldier";
- this.accountNumber=Integer.parseInt("5" + id);
- this.limit=3000;
- if(age>18){
- this.age=age;
- }
- else
- ageExcepptions.ageExcepptionsSoldier();
- }
- }
- ==============================================================================
- package bank;
- import java.util.InputMismatchException;
- public class Student extends loanFunctionOnAble {
- public Student(String name, int id, int age ) throws exceptionsAccount {
- super(name, id, age);
- this.studentCount+=1;
- this.age=age;
- fee=0.001;
- this.loan=0;
- this.payment=0;
- this.typeOfaccount="Student";
- this.accountNumber=Integer.parseInt("3" + id);
- this.loanPaymentLeft=0;
- this.paymentValue=0.00;
- this.limit=5000;
- if(age>18){
- this.age=age;
- }
- else
- ageExcepptions.ageExcepptionsStudent();
- }
- }
- ==========================================================================
- package bank;
- public class Teenage extends Account {
- public Teenage(String name, int id, int age) throws exceptionsAccount {
- super(name, id, age
- );
- // TODO Auto-generated constructor stub
- teenageCount+=1;
- fee=0.00;
- this.limit=1000;
- this.accountNumber=Integer.parseInt("4" + id);
- if(age<18){
- this.age=age;
- }
- else
- ageExcepptions.ageExcepptionsTeenage();
- }
- }
- ======================================================================
- package bank;
- public class withDrawException extends exceptionsAccount {
- public withDrawException (String msg){
- super(msg);
- }
- public static void withDrawException() throws exceptionsAccount{
- throw new exceptionsAccount ("you can with drow between 50 - ");
- }
- }
- =======================================================================
Advertisement
Add Comment
Please, Sign In to add comment