Results 1 to 2 of 2
- 10-18-2011, 04:20 AM #1
Member
- Join Date
- Oct 2011
- Posts
- 10
- Rep Power
- 0
wrong accumulated service Charge in banking system
I just made a program for banking account
But When i put initial balance let say $500 and put a "1" code to withdraw
and finally put amount of money i want to withdraw from the balance.
But ServiceCharge has to be accumulated in the CheckingAccount class but
It seems they are not accumulated in the class.
I think i made wrong loop structure but not sure what it is.
Java Code:import javax.swing.JOptionPane; public class BankAccount { static CheckingAccount check; static String input; static double initialBalance; static double transAmount; static double serviceCharge; static double currentBalance; static double toServiceCharge; static private double below500Charge = 5.00; static private double below0Charge = 10.00; static private double checkCharge = 0.15; static private double depositCharge = 0.10; static int transCode; public static void main(String[] args) { initialBalance = getInitialBalance(); // get initial balance check = new CheckingAccount(); // create CheckAccount class check.setBalance(initialBalance); // pass initial balance to CheckAccount class transCode = getTransCode(); // get trans code check.setTransCode(transCode); // pass trans code to CheckingAccount class //iteration until terminate the program while(transCode == 1 || transCode == 2){ // iteration as long as trans code is 1 or 2 if(transCode == 1){ transAmount = getTransAmount(); // get trans amount check.setTransAmount(transAmount); // pass trans amount to CheckingAccount class processChecking(); // display result of transaction transCode = getTransCode(); // get trans code again to iterate the loop check.setTransCode(transCode);// pass trans code to CheckingAcount class } else processDeposit(); } processEnding(); } public static double getInitialBalance() { double balance; input = JOptionPane.showInputDialog("Enter your initial balance: "); balance = Double.parseDouble(input); return balance; } public static int getTransCode() { int trCode; input = JOptionPane.showInputDialog("Enter the trans code: "); trCode = Integer.parseInt(input); return trCode; } public static double getTransAmount(){ double tAmount; input = JOptionPane.showInputDialog("Enter the trans amount: "); tAmount = Double.parseDouble(input); return tAmount; } public static void processChecking() { // charge $ 5 only once when balance is below $ 500 currentBalance = check.getBalance(); serviceCharge = check.getServiceCharge(); transAmount = check.getTranAmount(); if(currentBalance < 500){ serviceCharge = below500Charge; check.setServiceCharge(serviceCharge); //pass service charge to CheckingAccount class if(currentBalance < 0){ // if balance is less than $ 0 serviceCharge += checkCharge; // when account was withdrew, service fee charged by $ 0.15 serviceCharge += below0Charge; // when account balance is below $ 0, service fee charged by $10 check.setServiceCharge(serviceCharge); // pass to CheckingAccount class JOptionPane.showMessageDialog(null, "Transaction : Check in Amount of $" + transAmount + "\nCurrent Balance : $ " + currentBalance + "\nService Charge : Check --- charge $ " + checkCharge + "\nWarning balance below $ 50" + "\nService Charge : Below $ 0 --- charge $ " + below0Charge + "\nTotal ServiceCharge : $ " + serviceCharge); } else if(currentBalance < 50){ serviceCharge += checkCharge; check.setServiceCharge(serviceCharge); JOptionPane.showMessageDialog(null, "Transaction : Check in Amount of $" + transAmount + "\nCurrent Balance : $ " + currentBalance + "\nService Charge : Check --- charge $ " + checkCharge + "\nWarning balance below $ 50" + "\nTotal ServiceCharge : $ " + serviceCharge); } else if(currentBalance < 500){ serviceCharge += checkCharge; check.setServiceCharge(serviceCharge); JOptionPane.showMessageDialog(null, "Transaction : Check in Amount of $" + transAmount + "\nCurrent Balance : $ " + currentBalance + "\nService Charge : Check --- charge $ " + checkCharge + "\nTotal ServiceCharge : $ " + serviceCharge); } } else{ serviceCharge += checkCharge; check.setServiceCharge(serviceCharge); JOptionPane.showMessageDialog(null, "Transaction : Check in Amount of $" + transAmount + "\nCurrent Balance : $ " + currentBalance + "\nService Charge : Check --- charge $ " + checkCharge + "\nTotal ServiceCharge : $ " + serviceCharge); } } public static void processDeposit() { } public static void processEnding() { } }
Java Code:public class CheckingAccount { double balance; double transCode; double transAmount; double totalServiceCharge; double serviceCharge; public void setBalance(double bal){ balance = bal; } public void setTransCode(int tCode){ transCode = tCode; } public void setTransAmount(double tAmount){ transAmount = tAmount; } public void setServiceCharge(double sCharge){ totalServiceCharge = sCharge; } public double getTransCode(){ return transCode; } public double getTranAmount(){ return transAmount; } public double getBalance(){ if(transCode == 1) balance = balance - transAmount; else if(transCode == 2) balance = balance + transAmount; return balance; } public double getServiceCharge(){ return totalServiceCharge += totalServiceCharge; } }
- 10-18-2011, 04:26 AM #2
Similar Threads
-
Why is the System Path wrong
By seeya73 in forum New To JavaReplies: 2Last Post: 09-20-2011, 04:04 PM -
Web Crawler for Online Banking
By foulkes in forum Advanced JavaReplies: 0Last Post: 09-05-2011, 09:22 PM -
Java Developer Positions New York City (Investment Banking Domain)
By Dave IRIS in forum Jobs OfferedReplies: 0Last Post: 12-28-2010, 05:08 PM -
Eclipse creates web service that returns an object but something's wrong...!!!
By nikos in forum EclipseReplies: 0Last Post: 10-13-2010, 06:26 PM -
3x wrong password will lock the system
By ashin in forum SWT / JFaceReplies: 0Last Post: 07-11-2009, 04:03 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks