Results 1 to 2 of 2
  1. #1
    wndtjr2 is offline Member
    Join Date
    Oct 2011
    Posts
    10
    Rep Power
    0

    Default 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;
    	}	
    }

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,800
    Rep Power
    7

    Default Re: wrong accumulated service Charge in banking system

    Java Code:
    public void setServiceCharge(double sCharge){
        totalServiceCharge = sCharge;
    }
    If you want the service charge to accumulate then I imagine some sort of addition would need to be performed.

Similar Threads

  1. Why is the System Path wrong
    By seeya73 in forum New To Java
    Replies: 2
    Last Post: 09-20-2011, 05:04 PM
  2. Web Crawler for Online Banking
    By foulkes in forum Advanced Java
    Replies: 0
    Last Post: 09-05-2011, 10:22 PM
  3. Replies: 0
    Last Post: 12-28-2010, 06:08 PM
  4. Replies: 0
    Last Post: 10-13-2010, 07:26 PM
  5. 3x wrong password will lock the system
    By ashin in forum SWT / JFace
    Replies: 0
    Last Post: 07-11-2009, 05:03 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •