hey pple, I have this banking program that I have build but it not running properly, somewhere along the codes, something is wrong, I dont what, I dont know if the calculation is wrong somewhere along the lilnes . I will post all of my classes so that you can get an idea what I am trying to say and I will also post the outcome when I run it and I will also explain it. what is supposed to be doing and it is not doing. so here goes. first one is the transaction account. after each class I will explain what each class supposed to do when it run
transaction account
this transaction account supposed to gave the amt of transaction, gave a new balance after this transaction and the description of the transaction and it is not doing that. it also should be ablto show the date of this transaction, the type of transaction such as "W", for withdrawal, "D' for deposit
second class is the saving account
this saving account supposed calculate the interest rate . and the constructor should initialize all of the parent variables. as well as my own.
next is the chequing account
this chequing account supposed to have an overdraft limit to which u can widthdraw more that you have and also override the widthdrawal and deposit methods that is to cater for the overdraft limit. also if the overdraft limit is 500, this means that once the balance is 0, the user has the ability to withdraw up to 500 however the balance should show up as -500,for e.g if the user deposit 300, the balance is -200 and to which it is not doing
next is the customer class
this class should stored all of the information of the customer.
up next is the account class
the acct class should be able to stored the transaction on the account stored in arraylist, withdraw and deposit methods to withdraw and deposit funds.
and this is my main
for e.g if the user clicked on the 'o' to open an account ( it keep loopin) here is the outcome
it keep looping
when u click on "d" to deposit, the outcome is this
public class Transaction_Account{ ArrayList <Transaction_Account> newtrans = new ArrayList(); private Date date; private double balance; private String description; private char type; private double total_amt; public Transaction_Account(Date date, char type, double balance, double total_amt, String description){ this.date = new Date(); this.type = type; this.balance = balance; this.total_amt = total_amt; this.description=description; } public Date getDate(){ return date; } public char gettype(){ return type; } public double getbalance(){ return balance; } public String getdescription(){ return description; } public double gettotal_amt(){ return total_amt; } public void setDate(Date date){ this.date=date; } public void settype(char type){ this.type=type; } public void setbalance(double balance){ this.balance = balance; } public void setdescription(String description){ this.description=description; } public void settotal_amt(double total_amt){ this.total_amt = total_amt; } @Override public String toString(){ return this.toString()+ "\n"+new Date()+" "+ "Type "+ this.type + " "+ "Account Balance"+ this.balance +" "+"Description"+ this.description; }
import java.util.Date; /** * * */ public class Saving_Account extends Account{ private float interestRate = 500; double balance; public Saving_Account(String firstname, String acctnum, double balance, float interestRate){ super(firstname, acctnum, balance); this.interestRate=interestRate; } public float getinterestRate(){ return interestRate; } public void setinterestRate(float interestRate){ this.interestRate = interestRate/100; } private double getBalance(double balance) { return balance; } public void setbalance(double balance){ this.balance = balance; } public void payInterest(){ double total_amt = getbalance(); double balance = 0; balance=(total_amt + (total_amt*getinterestRate())); setbalance(balance); System.out.print("Account Balance with interest is %.2f"+balance); Transaction_Account newtrans = new Transaction_Account(new Date(), 'I', balance,0,"Interest Paid"); transacct.add(newtrans); } //withdrawal method @Override public void withdraw(double total_amt){ double balance = 0; double acctamt = 0; if(acctamt < total_amt){ System.out.println("Insufficient funds, balance is :$"+ acctamt); } else{ balance = acctamt -= total_amt; setbalance(balance); System.out.print("The withdrawal of: $"+total_amt + " was succesful, the new balance is: $%.2f" + getBalance(balance)); Transaction_Account newtrans = new Transaction_Account(new Date(), 'W', balance, 0, "Withdraw Made"); transacct.add(newtrans); } } @Override public void deposit(double total_amt){ double balance; double acctamt = getbalance(); balance = acctamt+=total_amt; setbalance(balance); System.out.println("Your deposit amount is: $"+ total_amt + "was successful, the new balance is"+ balance); Transaction_Account newtrans = new Transaction_Account(new Date(), 'D', balance, 0, "deposit made"); transacct.add(newtrans); } @Override public String toString(){ return this.toString()+ "Interest Rate"+ interestRate; } }
public class Chequing_Account extends Account { private float overdraft ; double balance; public Chequing_Account(String firstname, String acctnum, double balance, float overdraft){ super(firstname, acctnum, balance); this.overdraft = overdraft; } public float getoverdraft(){ return overdraft=500; } public void setoverdraft(float overdraft){ if(balance > overdraft){ System.out.println("Sorry but the limit for the overdraft cannot be exceeded:$"+ overdraft); } } public void withdrawal(double total_amt){ double acctamt = getbalance(); double balance=0; if(total_amt > balance){ System.out.println("You can withdraw more than you have"); }else{ balance = acctamt-= total_amt; setbalance(balance); System.out.println("Insufficient funds available "); Transaction_Account newtrans= new Transaction_Account(new Date(), 'W', balance, 0, "Withdrawal made"); transacct.add(newtrans); } } @Override public void deposit(double total_amt){ double acctamt = getbalance(); double balance = 0; balance = acctamt+=total_amt; setbalance(balance); System.out.println("You have deposited: $"+total_amt+ "have been added to your account balance"+ "Your new balance is: $"+total_amt); Transaction_Account newtrans = new Transaction_Account(new Date(), 'D', balance,0,"Deposit deposited"); transacct.add(newtrans); } @Override public String toString(){ return this.toString()+ "Over Draft Limit"+ this.overdraft; } }
public class Customer { private String firstname; private String lastname; private String email_add; private String home_add; private String cellnum; public Customer(String firstname, String lastname, String email_add, String home_add, String cellnum){ this.firstname = firstname; this.lastname = lastname; this.email_add = email_add; this.home_add = home_add; this.cellnum= cellnum; } public String getfirstname(){ return firstname; } public String getlastname(){ return lastname; } public String getemail_add(){ return email_add; } public String gethome_add(){ return home_add; } public String getcellnum(){ return cellnum; } public void setfirst_name(String firstname){ this.firstname=firstname; } public void setlast_name(String lastname){ this.lastname=lastname; } public void setemail_add(String email_add){ this.email_add = email_add; }
public abstract class Account{ ArrayList <Transaction_Account> transacct = new ArrayList <>(); private double balance; String acctnum; String firstname; String lastname; public Account(String firstname, String acctnum, double balance){ this.firstname = firstname; this.acctnum = acctnum; this.balance = balance; } public String getfirstname(){ return firstname; } public String getlastname(){ return lastname; } public String acctnum(){ return acctnum; } public double getbalance(){ return balance; } public void setfirstname(String firstname){ this.firstname = firstname; } public void setlastname(String lastname){ this.lastname = lastname; } public void setacctnum(String acctnum){ this.acctnum = acctnum; } public void setbalance(double balance){ this.balance = balance; } public void withdraw(double total_amt){ if(balance < total_amt){ System.out.print("Sorry insufficient funds: $"+ balance); } else{ this.balance -= total_amt; System.out.println("\n "+ "Your current balance is"+this.balance); Transaction_Account newtrans = new Transaction_Account(new Date(), 'W', this.balance, 0, "Withdrawal made"); transacct.add(newtrans); } //end of the withdraw method } //start of the deposit method public void deposit(double total_amt){ this.balance +=total_amt; System.out.print("\n"+total_amt+"Your balance is:"+this.balance); Transaction_Account newtrans = new Transaction_Account(new Date(), 'D', balance,0, "Deposit deposited"); transacct.add(newtrans); } //end of the deposit method //toString method @Override public String toString(){ return "Customers details" + this.firstname+" "+this.lastname+" "+this.acctnum+" "+ +this.balance; } }
public class BankAccount { public static void main(String[]args){ Scanner keyin = new Scanner(System.in); ArrayList savings = new ArrayList(); ArrayList chequing = new ArrayList(); String firstname = null; String lastname; String home_add; String email_add; String cellnum; char type; double balance = 0; float interestRate = 0; String acctnum = null; double total_amt; char mychoice ; boolean choice = true; float overdraft = 0; Saving_Account sa = new Saving_Account(firstname, acctnum, balance, interestRate); Chequing_Account ca = new Chequing_Account(firstname, acctnum, balance, overdraft); System.out.println("\n"+ "Please select one of the following option"); System.out.println(" o - To open an account"); System.out.println(" d - To make a deposit"); System.out.println(" w - To make a withdraw"); System.out.println(" i - To pay the interest"); System.out.println(" t - To view the transactions"); System.out.println(" q - To quit"); type = keyin.next().trim().toUpperCase().toLowerCase().charAt(0); this part of the codes let the user choose which type of transaction they want to do but when I clicked on any one ot the letter the result is not what is supposed to do while(type != 'q'){ if(type == 'o'){ System.out.print("Enter which type of account(Savings-s)(Chequing-c)"); mychoice = keyin.next().trim().toUpperCase().toLowerCase().charAt(0); if(mychoice == 's'){ System.out.print("Enter your first name"); firstname = keyin.next(); System.out.print("Enter last name"); lastname = keyin.next(); System.out.print("Enter your address"); home_add = keyin.next(); System.out.println("Enter your email address"); email_add = keyin.next(); System.out.print("Enter your cell number"); cellnum = keyin.next(); System.out.print("Enter account number"); acctnum = keyin.next(); savings.add(acctnum); System.out.print("Enter initial balance:$"+ balance ); balance = keyin.nextDouble(); sa.setbalance(balance); System.out.print("Enter the interest rate"); interestRate = keyin.nextFloat(); sa.getinterestRate(); savings.add(acctnum); }else if(mychoice == 'c'){ System.out.print("Enter your first name"); firstname = keyin.next(); System.out.print("Enter your last name"); lastname = keyin.next(); System.out.print("Enter your home address"); home_add = keyin.next(); System.out.print("Enter your email address"); email_add = keyin.next(); System.out.print("Enter your contact number "); cellnum = keyin.next(); System.out.print("Enter chequing account number"); acctnum = keyin.next(); chequing.add(acctnum); System.out.print("Enter the initial balance: $"+balance); balance= keyin.nextDouble(); ca.setbalance(balance); System.out.print("Enter overdraft limit"); overdraft = keyin.nextFloat(); } }else if(type == 'd'){ System.out.print("Which account to you wish to deposit"); if(savings.contains(acctnum)){ System.out.print("Enter the amount you want to deposit"); total_amt = keyin.nextDouble(); sa.deposit(total_amt); System.out.print("Total balance account is:$"+balance); balance = keyin.nextDouble(); } }else if(type == 'w'){ System.out.print("Which account you want to withdraw from"); acctnum = keyin.next(); if(savings.contains(acctnum)){ System.out.print("Enter the amount that you want to withdraw"); total_amt = keyin.nextDouble(); ca.withdraw(total_amt); } }else if(savings.contains(acctnum)){ sa.payInterest(); }else{ System.out.print(""); } }if(type == 't'){ System.out.print("Enter an account number"); acctnum = keyin.next(); if(savings.contains(acctnum)){ System.out.print("\n"+ "List of transaction done on this savings account"); System.out.print(sa.transacct.toString()); }else if(chequing.contains(acctnum)){ System.out.print("\n" + "List of transaction done on this chequing account"); System.out.print(ca.transacct.toString()); } }else if(type == 'q'){ } } }
Enter which type of account(Savings-s)(Chequing-c) c Enter your first name jen Enter your last name zen Enter your home address port of spain Enter your email addressEnter your contact number Enter chequing account number jzen@mail.com Enter the initial balance: $0.0 200 Enter overdraft limit 500 Enter which type of account(Savings-s)(Chequing-c)