Results 1 to 3 of 3
Thread: Need help with my bank class
- 11-15-2011, 03:49 PM #1
Member
- Join Date
- Sep 2011
- Posts
- 14
- Rep Power
- 0
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.
and this is my public 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 } }
Can anyone tell me the correct method for moving the account money back and forth between theJava 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 */ } }
two account?(checking and savings account)Last edited by JosAH; 11-15-2011 at 04:05 PM. Reason: fixed a couple of broken tags.
- 11-15-2011, 04:02 PM #2
Re: Need help with my bank class
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.the correct method for moving the account money back and forth between the two account?
- 11-21-2011, 03:39 PM #3
Member
- Join Date
- Sep 2011
- Posts
- 14
- Rep Power
- 0
Similar Threads
-
basic bank account
By captain_turkiye in forum New To JavaReplies: 5Last Post: 10-16-2011, 05:15 PM -
help java bank....
By natsuki in forum IntroductionsReplies: 2Last Post: 07-25-2011, 03:36 AM -
Create a java class for a bank account!!?
By singh345 in forum New To JavaReplies: 1Last Post: 03-17-2010, 04:26 PM -
Bank Account
By HPcompaq256 in forum New To JavaReplies: 11Last Post: 02-26-2010, 09:05 PM -
Code bank
By Eranga in forum Suggestions & FeedbackReplies: 2Last Post: 01-01-2008, 05:23 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks