Results 1 to 3 of 3
  1. #1
    rpark712 is offline Member
    Join Date
    Sep 2011
    Posts
    14
    Rep Power
    0

    Default Need help with my bank class

    Hello, I've been trying to make a bank class in my PAP-CS.
    This is the code for my bank class.

    Java Code:
    class Bank				
    {	
    	
    	///////////  ATTRIBUTES  //////////
    			
    	private double checkingBal;		
    	private double savingsBal;			
    	
    	
    	//////////  CONSTRUCTOR METHODS  //////////
    	public Bank()					
    	{
    		checkingBal = 0.0;
    		savingsBal = 0.0;
    	}
    	
    	///////////////////////////////////////////////
    	
    	public Bank(double cBal, double sBal)					
    	{
    		checkingBal = cBal;
    		savingsBal = sBal;
    	}
    	
    	
    	//////////  GET "READ-ONLY" METHODS  //////////
    	public double getChecking()
    	{
    		return checkingBal;
    	}	
    	
    	///////////////////////////////////////////////
    		
    	public double getSavings()
    	{
    		return savingsBal;
    	}
    	
    	///////////////////////////////////////////////
    	
    	public double getCombined()
    	{
    		return savingsBal+checkingBal;
    	}
    	
    	//////////  SET or MUTATOR "READ/WRITE" METHODS  //////////
    	public void checkingDeposit(double amount)
    	{
    		checkingBal += amount;
    	}	
    		
    	///////////////////////////////////////////////	
    		
    	public void savingsDeposit(double amount)
    	{
    		savingsBal += amount;
    	}
    	
    	///////////////////////////////////////////////
    	
    	public void checkingWithdrawal(double amount)
    	{
    		if (amount > checkingBal)
    		{System.out.println("Insufficient Funds!  Transaction Refused!\n");
    		 //need help
    		}	
    		/*  if the account for checking and the combined doesn't have any money
    		for the withdrawal it rejects the check and fines $40  */
    		
    		else if (savingsBal+checkingBal >= amount)	
    		{
    			// need help
    		}
    		/*  if the account doesn't have enough money in the checking,
    		but has enough for combined. The system moves the money from the 
    		savings and puts it in the checking account to avoid fines  */
    		
    		else
    		checkingBal -= amount;
    		// if the account has enough money it takes the money directly
    	}
    	
    	///////////////////////////////////////////////
    	
    	public void savingsWithdrawal(double amount)
    	{
    		if (amount > savingsBal)
    		{System.out.println("Insufficient Funds!  Transaction Refused!\n");
    		 //need help
    		}
    		/*  if the account for savings and the combined doesn't have any money
    		for the widthdrawal it rejects the check and fines $40  */
    		
    		else if (savingsBal+checkingBal >= amount)	
    		{
    			//need help
    		}
    		/*  if the account doesn't have enough money in the savings, 
    		but has enough for combined. The system moves the money from the 
    		checking and puts it in the savings account to avoid fines  */
    		
    		else 
    		savingsBal-=amount;
    		// if the account has enough money it takes the money directly
    	}				
    			
    }
    and this is my public class.


    Java Code:
    public class TextLab05 
    {
    
        public static void main(String args[]) 
        {
        	Bank tom = new Bank(0.0,0.0);
    		Bank sue = new Bank(3000.0,0.0);
    		Bank bob = new Bank(5000.0,10000.0);
    		//creates the banks
    		
    		System.out.println();
    		System.out.println("Text Lab 05");
    		System.out.println();
    		System.out.println();
    		System.out.println("Account balances for Tom Smith");
    		System.out.println("Checking: $" + tom.getChecking());
    		System.out.println("Savings:  $" + tom.getSavings());
    		System.out.println("Combined: $" + tom.getCombined());
    		//account balance for Tom
    		System.out.println();
    		System.out.println();
    		System.out.println("Account balances for Sue Brown");
    		System.out.println("Checking: $" + sue.getChecking());
    		System.out.println("Savings:  $" + sue.getSavings());
    		System.out.println("Combined: $" + sue.getCombined());
    		//account balance for Sue
    		System.out.println();
    		System.out.println();
    		System.out.println("Account balances for Bob Jones");
    		System.out.println("Checking: $" + bob.getChecking());
    		System.out.println("Savings:  $" + bob.getSavings());
    		System.out.println("Combined: $" + bob.getCombined());
    		//account balance for Bob
    		
    		System.out.println();
    		System.out.println();
    		//space
    		
    		System.out.println("Tom deposits $1000 in checking and $5000 in savings.");
    		//the action
    		
    		System.out.println();
    		System.out.println();
    		//space
    		
    		tom.checkingDeposit(1000.0);
    		tom.savingsDeposit(5000.0);
    		//Deposits for Tom
    		
    		System.out.println("Account balances for Tom Smith");
    		System.out.println("Checking: $" + tom.getChecking());
    		System.out.println("Savings:  $" + tom.getSavings());
    		System.out.println("Combined: $" + tom.getCombined());
    		//new account balance for Tom
    		
    		System.out.println();
    		System.out.println();
    		//space
    		
    		System.out.println("Bob withdraws $4000 from checking.");
    		//the action
    		
    		System.out.println();
    		System.out.println();
    		//space
    		
    		bob.checkingWithdrawal(4000.0);
    		//withdraw for bob
    		
    		System.out.println("Account balances for Bob Jones");
    		System.out.println("Checking: $" + bob.getChecking());
    		System.out.println("Savings:  $" + bob.getSavings());
    		System.out.println("Combined: $" + bob.getCombined());
    		//new account balance for Bob
    			
    		System.out.println();
    		System.out.println();
    		//space
    		
    		System.out.println("Tom withdraws $4000 from checking.");
    		//the action
    		
    		System.out.println();
    		System.out.println();
    		//space
    		
    		tom.checkingWithdrawal(4000.0);
    		
    		/* I need the Bank class to execute an overdraft protection, so that the
    		 checking account does not suffer a $40 fine. I need to find how to transfer
    		 the money between the two accounts */
        }
    }
    Can anyone tell me the correct method for moving the account money back and forth between the
    two account?(checking and savings account)
    Last edited by JosAH; 11-15-2011 at 04:05 PM. Reason: fixed a couple of broken tags.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,266
    Rep Power
    25

    Default Re: Need help with my bank class

    the correct method for moving the account money back and forth between the two account?
    One way would be to subtract it from one (if the balance is high enough and there is no overdraw protection) and to add it to the other.

  3. #3
    rpark712 is offline Member
    Join Date
    Sep 2011
    Posts
    14
    Rep Power
    0

    Default Re: Need help with my bank class

    Thank you very much. That worked perfectly.

Similar Threads

  1. basic bank account
    By captain_turkiye in forum New To Java
    Replies: 5
    Last Post: 10-16-2011, 05:15 PM
  2. help java bank....
    By natsuki in forum Introductions
    Replies: 2
    Last Post: 07-25-2011, 03:36 AM
  3. Create a java class for a bank account!!?
    By singh345 in forum New To Java
    Replies: 1
    Last Post: 03-17-2010, 04:26 PM
  4. Bank Account
    By HPcompaq256 in forum New To Java
    Replies: 11
    Last Post: 02-26-2010, 09:05 PM
  5. Code bank
    By Eranga in forum Suggestions & Feedback
    Replies: 2
    Last Post: 01-01-2008, 05:23 AM

Posting Permissions

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