Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: Simple Banking System

  1. #1
    Junior Member
    Join Date
    Mar 2011
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Simple Banking System

    I want to make a Simple Banking System. I am bit confused.
    There will be some duties in the bank
    recieveCash
    sendCash

    1 variable called
    balance

    When someone uses recieveCash, it will increase the balance, when someone spends it will decrease the balance

    1 method called getBalance will show the balance of cash in the Bank. getBalance will print. getBalance should be private.

    Please Help


  2. #2
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Cool Re: Simple Banking System

    Quote Originally Posted by ShadowKing98 View Post
    I want to make a Simple Banking System. I am bit confused.
    There will be some duties in the bank
    recieveCash
    sendCash

    1 variable called
    balance

    When someone uses recieveCash, it will increase the balance, when someone spends it will decrease the balance

    1 method called getBalance will show the balance of cash in the Bank. getBalance will print. getBalance should be private.

    Please Help


    Ok, you've said nothing on how you want to go about doing this?

    receive cash and send cash sound like they are supposed to be methods.

    balance should probably be a double or float variable I think.


    I think you should also have a method called setBalance.

    Also, was balance supposed to be private or getBalance?


    A setter method looks like this(oh, and make sure to have some other type of class variable, i.e. one defined at the beginning with variable declarations.
    Like so:
    private double balance;


    Anyway, a setter method looks like this, using the variable defined above when I'm referring to this.balance (this is an object's reference to itself).
    public void setBalance(double balance)
    {
    this.balance=balance;
    }

    This method will print balance.

    private void getBalance()
    {
    System.out.println(balance);
    }

    I'd recommend that for send cash and receive cash, you make them setter methods and pass them a double variable called cash as a parameter.

    Then I recommend you call setBalance with balance +- cash as parameter.

    Also, you should have something like
    if ((balance-cash) < 0)
    {
    System.out.println("Cannot withdraw this amount!");
    return;
    }

    This will exit the method and stop the account from going into the negative.


    To have a method call another method inside itself, do something like this:
    setBalance(balance + cash);


    Ask if you have any more questions.




    Can't say how to implement it, (GUI or command prompt as you didn't specify that.)
    Last edited by javapenguin; April 9th, 2011 at 09:02 PM. Reason: Editing

  3. #3
    Junior Member
    Join Date
    Mar 2011
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Simple Banking System

    Im kinda a noob. Yes getBalance was supposed to be private. Could you tell me how to build it with return values only. And please tell me where to put the code. Oh yeah it doesnt really matter where to implement it. Could you tell me should I make a new class or do I put it in main. Please tell me where to put the pieces of code you gave me

    Please
    Last edited by ShadowKing98; April 10th, 2011 at 05:51 AM.

  4. #4
    Junior Member
    Join Date
    Mar 2011
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Simple Banking System

    package bankassignment;
     
     
     
    public class Main {
     
     
     
        public static void main(String[] args) {
     
        }
     
    }

    Please tell me where to put the pieces of code

  5. #5
    Forum Squatter newbie's Avatar
    Join Date
    Nov 2010
    Location
    North Wales
    Posts
    661
    My Mood
    Stressed
    Thanks
    28
    Thanked 115 Times in 106 Posts
    Blog Entries
    1

    Default Re: Simple Banking System

    JavaPenguin, spoon feeding to that extent when he showed such very little effort will not help him.
    If he can't do the basics himself, he will keep coming back asking 'ok what next?', as he won't have a hope in hell of doing the rest of the code.
    Would have been more beneficial to provide him with some reading material and tutorials.
    Please use [highlight=Java]//code goes here...[/highlight] tags when posting your code

  6. The Following User Says Thank You to newbie For This Useful Post:

    copeg (April 10th, 2011)

  7. #6
    Junior Member
    Join Date
    Mar 2011
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Simple Banking System

    OK please help me out newbie

  8. #7
    Forum Squatter newbie's Avatar
    Join Date
    Nov 2010
    Location
    North Wales
    Posts
    661
    My Mood
    Stressed
    Thanks
    28
    Thanked 115 Times in 106 Posts
    Blog Entries
    1

    Default Re: Simple Banking System

    As I don't quite know how much experience you have with Java, i'll point you here.
    Trail: Learning the Java Language (The Java™ Tutorials)

    The first three topics should be sufficient.
    - Feel free to come back with questions if you're not sure on a particular topic.
    Please use [highlight=Java]//code goes here...[/highlight] tags when posting your code

  9. #8
    Super Moderator Json's Avatar
    Join Date
    Jul 2009
    Location
    Warrington, United Kingdom
    Posts
    1,274
    My Mood
    Happy
    Thanks
    70
    Thanked 156 Times in 152 Posts

    Default Re: Simple Banking System

    This might be slightly off topic for you but I would probably have the balance and any other monetary amounts as data type of long and then remove the decimal point.

    The reason being that different operating systems have different floating point precision. Otherwise you could set the balance as a strictfp float but I'd still go with longs.

    This might not be too much of an issue for you though but be careful with floating point comparisons.

    // Json

Similar Threads

  1. Banking Application
    By mbouster in forum Object Oriented Programming
    Replies: 2
    Last Post: January 9th, 2011, 11:23 AM
  2. urgent simple help for a very simple program
    By albukhari87 in forum Java Applets
    Replies: 4
    Last Post: June 5th, 2010, 03:43 PM
  3. Replies: 8
    Last Post: December 9th, 2009, 04:45 PM
  4. not so simple, simple swing question box
    By wolfgar in forum AWT / Java Swing
    Replies: 2
    Last Post: November 20th, 2009, 03:47 AM
  5. System.CurrentTimeMilliseconds
    By Dave in forum Java SE APIs
    Replies: 1
    Last Post: August 26th, 2009, 11:02 AM