hi I have build this program and for some reason it is not running how it supposed to run. I am going to put all of my classes, the result (what happen when it run) and the result on how it supposed to run.
first to begin is the customer class
and this is my main
when I run the program this is the result I get, the result below is now how is supposed to run, it supposed to run until the user type the q-quit.
Please select one of the following option
o - To open an account
d - To make a deposit
w - To make a withdraw
i - To pay the interest
t - To view the transactions
q - To quit
BUILD STOPPED (total time: 5 seconds)
ths result below is how is it supposed to run until the user quit the program, which is the q-quite/exist button
Open Account
Enter which type of account (Savings-s) (Checking-c): s
First Name: Peter
Last Name: Pan
Address: POS
Email: peter.pan@wonderland.com
Contact: 921-4324
Enter account number: 1234
Enter balance: $1000.00
Enter interest rate: 0.02
Enter which type of account (Savings-s)(Checking-c) : c
First Name: Tinker
Last Name: Bell
Address: Neverland
Email: tinkerbell@neverland.com
Contact: 232-3424
Enter account number: 2134
Enter balance: $5000.00
Overdraft Limit: $400.00
Deposit
Which account to you wish to deposit: 1234
Amount: 521.00
Current Balance of account 1234: 1521.00
Withdraw
Which account to you wish to withdraw from: 2134
Amount: 500.00
Current Balance of account 1234: 1021
Pay Interest
Enter command: I (N.B will list the new balances for ALL Savings Accounts)
New Balances
--------------------
1234 $1041.42
Transaction
Select an account: 1234
List of Transactions: (N.B. Please note that you must list ALL the transactions done on the account)
1. Date: 12/09/2019
Transaction type: D
Amount: 521.00
Balance: 1521.00
Description: Withdrawal from account.
2. Date: 14/11/2019
Transaction type: W
Amount: 500.00
Balance: 1021.00
Description: Withdrawal from account.
Quit
any help will do thanks in advance
public class Customer { private String firstname; private String lastname; private String gender; private int contact; public Customer(String firstname, String lastname, String gender, int contact){ this.firstname = firstname; this.lastname = lastname; this.gender = gender; this.contact = contact; } Customer() {} public String getfirstname(){ return firstname; } public String getlastname(){ return lastname; } public String getgender(){ return gender; } public int getcontact(){ return contact; } public void setfirstname(String firstname){ this.firstname = firstname; } public void setlastname(String lastname){ this.lastname = lastname; } public void setcontact(int contact){ this.contact = contact; } @Override public String toString(){ return "\n"+ "Customer details"+ "\n "+"Customer first name is"+firstname+ "\n"+"Customer last name is:"+lastname+ "Customer gender is: "+"\n"+ gender+"Customer contact is:"+ "\n"+contact; } } second is the account class public abstract class Account{ ArrayList <Transaction_Account> transaction = new ArrayList <>(); private double balance; String acctnum; String firstname; String lastname; String cellnum; String home_add; String email_add; public Account(String firstname, String acctnum, double balance){ this.firstname = firstname; this.acctnum = acctnum; this.balance = balance; } public String getfirst_name(){ return firstname; } public String getlast_name(){ return lastname; } public String gethome_add(){ return home_add; } public String getemail_add(){ return email_add; } public String acctnum(){ return acctnum; } public double getbalance(){ return balance; } public void setfirstname(String first_name){ this.firstname = first_name; } public void setlastname(String lastname){ this.lastname = lastname; } public void sethome_add(String home_add){ this.home_add = home_add; } public void setemail_add(String email_add){ this.email_add = email_add; } 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,0, "Withdrawal made"); transaction.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,0, "Deposit deposited"); transaction.add(newtrans); } //end of the deposit method //toString method @Override public String toString(){ return "Customers details" + this.firstname+" "+this.lastname+" "+this.acctnum+" "+ this.home_add+" "+" "+this.email_add +" "+this.balance; } } this is the transaction class import java.util.ArrayList; import java.util.Date; /** * * @author Luana */ 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; double newbalance; public Transaction_Account(Date date, char type, double balance, double total_amt,double newbalance, String description){ this.date = new Date(); this.type = type; this.balance = balance; this.total_amt = total_amt; this.newbalance= newbalance; 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 double getnewbalance(){ double newbalance = balance - total_amt; setbalance(this.balance); return this.newbalance; } 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; } public void setnewbalance(double newbalance){ this.newbalance = newbalance; } @Override public String toString(){ return "\n"+new Date()+" "+ "Type "+ this.type + " "+ "Account Balance"+ this.balance +" "+"Description"+ this.description; } fourth is the saving account class import java.util.Date; /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * * @author Luana */ 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,0,"Interest Paid"); transaction.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,0, "Withdraw Made"); transaction.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,0, "deposit made"); transaction.add(newtrans); } @Override public String toString(){ return this.toString()+ "Interest Rate"+ interestRate; } } and lastly this is the chequing account class import java.util.Date; /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * * @author Luana */ public class Chequing_Account extends Account { private float overdraft = 500; double balance; public Chequing_Account(String firstname, String acctnum, double balance){ 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 && total_amt < 0){ System.out.println("I'm sorry but you exceeded over your limit"); } else{ balance = acctamt-=total_amt; setbalance(balance); System.out.println("Insufficient funds available "); Transaction_Account newtrans= new Transaction_Account(new Date(), 'W', balance, 0,0, "Withdrawal made"); transaction.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,0,"Deposit deposited"); transaction.add(newtrans); } @Override public String toString(){ return this.toString()+ "Over Draft Limit"+ this.overdraft; } }
import java.util.Scanner; /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * * @author User */ 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; char type; double balance = 0; float interestRate = 0; String acctnum = null; double total_amt; char yourchoice; Saving_Account sa = new Saving_Account(firstname, acctnum, balance, interestRate); Chequing_Account ca = new Chequing_Account(firstname, acctnum, balance); 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); while(type !='q'){ if(type == 'o'){ System.out.print("Please select the type of account you will like to open: s-Saving or c-Checking"); yourchoice = keyin.next().trim().toUpperCase().toLowerCase().charAt(0); if(yourchoice == 's'){ System.out.print("Please enter account holder"); firstname = keyin.next(); System.out.print("please enter the Saving Account Number"); acctnum = keyin.next(); savings.add(acctnum); System.out.print("Please enter a starting balance"); balance = keyin.nextDouble(); sa.setbalance(balance); System.out.print("Please enter the recent interest rate"); interestRate = keyin.nextFloat(); sa.setinterestRate(interestRate); savings.add(acctnum); } else if(yourchoice == 'c'){ System.out.print("Please enter your chequing account number"); acctnum = keyin.next(); chequing.add(acctnum); System.out.print("Please enter a starting balance"); balance = keyin.nextDouble(); ca.setbalance(balance); } else if(type == 'd'){ System.out.print("Please enter the account number to wish you to make a deposit to"); acctnum = keyin.next(); if(savings.contains(acctnum)){ System.out.print("Please enter how much you would like to delposit to your saving account"); total_amt = keyin.nextDouble(); sa.deposit(total_amt); } else if(chequing.contains(acctnum)){ System.out.print("Please enter the amount that you wouldlike to deposit to your chequing account"); total_amt = keyin.nextDouble(); ca.deposit(total_amt); } else if(type == 'w'){ System.out.print("Please enter your account number"); acctnum = keyin.next(); if(savings.contains(acctnum)){ System.out.print("Please enter the aount that you wish to withdraw from your savings account"); total_amt =keyin.nextDouble(); sa.withdraw(total_amt); } else if(chequing.contains(acctnum)){ System.out.print("Please enter the aount that you would like to withdraw from your chequing account"); total_amt = keyin.nextDouble(); ca.withdrawal(total_amt); } else if(type == 'i'){ System.out.print("Please enter your account number"); acctnum = keyin.next(); if(savings.contains(acctnum)){ sa.payInterest(); } else { System.out.print("This is not your saving account, I'm sorry"); } if(type == 't'){ System.out.print("Please enter an account number"); acctnum = keyin.next(); if(savings.contains(acctnum)){ System.out.print("\n"+ "Transaction description for the account: %s"+ acctnum); System.out.print(sa.transaction.toString()); } else if(chequing.contains(acctnum)){ System.out.print("\n"+ "Transaction description for the account: %s"+acctnum); System.out.print(ca.transaction.toString()); } else if(type == 'q'){ break; } 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); } } } } } }