Page 1 of 2 12 LastLast
Results 1 to 20 of 30
Like Tree2Likes

Thread: Need help with basic bank program

  1. #1
    dmp5658 is offline Member
    Join Date
    Sep 2016
    Posts
    33
    Rep Power
    0

    Default Need help with basic bank program

    I am very new to coding and need help with a bank program, I have gone through many tutorials, even the ones posted here about a bank program and still don't fully understand.

    The requirements for the program are the following
    Need help with basic bank program-ss-2016-09-13-11.40.17-.png

    I'm stuck and don't really know how I should continue the program
    so far I have this

    Account.java
    Java Code:
    public class Account {
        private double balance;
        private String name;
        private long acctNum;
    
        public Account(String owner, long number) {
            balance = 0;
            name=owner;
            acctNum=number;
    
        }
    
        public Account() {
    
        }
    
        public void withdraw(double amount) {
            if(amount>0){
                if (amount<=balance){
                    balance= balance - amount;
                }}
            else
                System.out.println("Invalid withdraw amount!");
        }
    
        public void deposit(double amount) {
            if(amount>0) {
                balance = balance + amount;
            }
            else
                System.out.println("Cannot deposit negative number!");
        }
    
        public double getBalance() {
            return balance;
        }
    
        public String get_name()
        {
            return name;
        }
    
        public long get_account_number()
        {
            return acctNum;
        }
    
    
    
    }



    Test.Java
    Java Code:
    public class Test  {
        public static void main(String[] args) {
    
    
            Account acc1=new Account();
            acc1.deposit(99);
    
            Account acct2 = new Account();
            acct2.deposit(100);
    
            System.out.println(acc1.getBalance());
            System.out.println(acct2.getBalance());
    
    
    
        }
    
    
    
    
    
    
    }

    Any well will be greatly appreciated

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    27

    Default Re: Need help with basic bank program

    What issues are you having?
    Where are you stuck?

    I do notice you are missing an attribute for the class.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    dmp5658 is offline Member
    Join Date
    Sep 2016
    Posts
    33
    Rep Power
    0

    Default Re: Need help with basic bank program

    I'm not sure how to finish the program, like what I want the program to do is basically let me add different bank accounts with name and account # and then display it and I'm not sure how to do that

  4. #4
    dmp5658 is offline Member
    Join Date
    Sep 2016
    Posts
    33
    Rep Power
    0

    Default Re: Need help with basic bank program

    Well my main goal is to have it display account name, number, and balance for several accounts but I don't know what to do. What attribute is it that I missed? Thanks

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    27

    Default Re: Need help with basic bank program

    I would copy and paste the text, but it's an image.
    Re-read the second sentence in the requirements you posted above and compare with the attributes you've written.

    The requirements simply state that your main() method should test the Account class by doing a series of withdrawals and deposits.
    So I would have created a single Account and deposit some, check the balance matches what you expect, then deposit some more, and check, then deposit a negative amount and check the balance doesn't change, then withdraw some etc etc.

    You essentially need to test each of the requirements.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  6. #6
    dmp5658 is offline Member
    Join Date
    Sep 2016
    Posts
    33
    Rep Power
    0

    Default Re: Need help with basic bank program

    I forgot the account type, thank you but how can I limit it between the two options of checking and savings?

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    27

    Default Re: Need help with basic bank program

    If you've done enums then an enum.
    If not then possibly two constant Strings and check that the value passed into the setAccountType is one of those Strings?

    ETA: Actually, the requirements you posted don't mention what values are allowed, so maybe don't worry about that at he moment?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  8. #8
    dmp5658 is offline Member
    Join Date
    Sep 2016
    Posts
    33
    Rep Power
    0

    Default Re: Need help with basic bank program

    Alright thank you for all the help Tolls, it is greatly appreciated, one more question, how can I tie it all together and have it enter and print out the account name+account number+account type+balance on the test class, thank you once again

  9. #9
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: Need help with basic bank program

    Just use your getters for each acct and concatenate them together as appropriate in a System.out.println statement.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  10. #10
    dmp5658 is offline Member
    Join Date
    Sep 2016
    Posts
    33
    Rep Power
    0

    Default Re: Need help with basic bank program

    What am I doing wrong here? I added my sets and gets and it still shows up with errors on my test.java when I'm trying to add an account and add the name and such to it
    Java Code:
    public class Account {
        private double balance;
        private String name;
        private String accType;
        private long acctNum;
    
    
        public Account(String name, long acctNum, String accType, double balance) {
            this.name=name;
            this.acctNum=acctNum;
            this.accType=accType;
        }
    
    
        public void withdraw(double amount) {
            if(amount>0){
                if (amount<=balance){
                    balance= balance - amount;
                }}
            else
                System.out.println("Invalid withdraw amount!");
        }
    
        public void deposit(double amount) {
            if(amount>0) {
                balance = balance + amount;
            }
            else
                System.out.println("Cannot deposit negative number!");
        }
    
       public void setBalance(double Balance){
           this.balance= balance;
       }
        public void setName(String name){
            this.name= name;
        }
        public void setaccType(String accType){
            this.accType= accType;
        }
        public void setacctNum(long actcNum){
            this.acctNum= acctNum;
        }
    
    
    
        public double getBalance() {
            return this.balance;
        }
    
        public String getName()
        {
            return this.name;
        }
    
        public long getaccNum()
        {
            return this.acctNum;
        }
    
        public String getaccType()
        {
            return this.accType;
        }
    
    
    
    
    }


    Test.Java
    Java Code:
    public class Test  {
        public static void main(String[] args) {
    
    
            Account acc1=new Account("David", "34534224", "Checking");
            acc1.deposit(99);
    
    
    
    
    
        }
    
    
    
    
    
    
    }
    
    
    
    
    
    
    
    
    
    
    
    }
    Last edited by dmp5658; 09-14-2016 at 09:06 PM.

  11. #11
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: Need help with basic bank program

    shows up with errors
    Please copy the full text of the error message and paste it here. It has important info about the error.
    If you don't understand my response, don't ignore it, ask a question.

  12. #12
    dmp5658 is offline Member
    Join Date
    Sep 2016
    Posts
    33
    Rep Power
    0

    Default Re: Need help with basic bank program

    Need help with basic bank program-1234.png

  13. #13
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: Need help with basic bank program

    You constructor takes four arguments, not three.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  14. #14
    benji2505 is offline Senior Member
    Join Date
    Sep 2014
    Location
    MA, USA
    Posts
    399
    Rep Power
    6

    Default Re: Need help with basic bank program

    ... and the account number is supposed to be a long, not a string.

  15. #15
    dmp5658 is offline Member
    Join Date
    Sep 2016
    Posts
    33
    Rep Power
    0

    Default Re: Need help with basic bank program

    Need help with basic bank program-hhh.png Still getting this error, I'm completely lost

  16. #16
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: Need help with basic bank program

    The image is hard to read. Could you copy the compiler's error message and paste it here?

    The message should show the source with a ^ under the location of the error.
    Here is a sample from the javac compiler:
    Java Code:
    TestSorts.java:138: cannot find symbol
    symbol  : variable var
    location: class TestSorts
             var = 2;
             ^
    If you don't understand my response, don't ignore it, ask a question.

  17. #17
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: Need help with basic bank program

    With the recommended changes, your code compiles just fine for me using Eclipse. Better ensure you are compiling the new changes.
    It might also help to post the new code. Finally, an unrelated problem you will have is that in your constructor, you don't save the
    balance.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  18. #18
    dmp5658 is offline Member
    Join Date
    Sep 2016
    Posts
    33
    Rep Power
    0

    Default Re: Need help with basic bank program

    Account.java
    Java Code:
    public class Account {
        private double balance;
        private String name;
        private String accType;
        private long acctNum;
    
    
        public Account(String name, long acctNum, String accType, double balance) {
            this.name=name;
            this.acctNum=acctNum;
            this.accType=accType;
        }
    
    
    
    
        public void withdraw(double amount) {
            if(amount>0){
                if (amount<=balance){
                    balance= balance - amount;
                }}
            else
                System.out.println("Invalid withdraw amount!");
        }
    
        public void deposit(double amount) {
            if(amount>0) {
                balance = balance + amount;
            }
            else
                System.out.println("Cannot deposit negative number!");
        }
    
       public void setName(String name){
           this.name= name;
       }
       public void setAccType(String accType){
           this.accType=accType;
       }
       public void setAcctNum (long acctNum){
           this.acctNum=acctNum;
       }
       public void setBalance (double balance){
           this.balance=balance;
       }
       public String getName(){
           return this.name;
       }
       public String getAccType(){
           return this.accType;
       }
       public long getAcctNum () {
           return this.acctNum;
       }
       public double getBalance () {
           return this.balance;
       }
    }




    Java Code:
    public class Test  {
        public static void main(String[] args) {
    
    
            Account acc1=new Account("David", 34534224, "Checking", 0);
            acc1.deposit(99);
    
    
    
    
    
        }
    
    
    
    
    
    
    }

    Thats the new code and the error code is
    Need help with basic bank program-new.png

    Once again thank you guys for the help

  19. #19
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: Need help with basic bank program

    Your IDE is either confused or you are not compiling the shown code. I can't tell because it compiles just fine for me.
    It looks like there might be another version of Account that is causing problems. I recommend you remove the existing
    class files and recompile.

    Regards,
    Jim
    dmp5658 likes this.
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  20. #20
    dmp5658 is offline Member
    Join Date
    Sep 2016
    Posts
    33
    Rep Power
    0

    Default Re: Need help with basic bank program

    I want to truly thank everyone who helped me, it compiles fine now it was just some weird unknown code that was at the top of my account.java before the class that I'm assuming I put in by mistake. Everything works now except I did some tests and its not giving me an error message once I withdraw more than whats on the account, my new test is
    Java Code:
    public class Test  {
        public static void main(String[] args) {
    
    
            Account acc1=new Account("David", 34534224, "Checking", 0);
            acc1.deposit(99);
    
            System.out.println("Account Name: " + acc1.getName());
            System.out.println("Account Number: " + acc1.getAcctNum());
            System.out.println("Account Type: " + acc1.getAccType());
            System.out.println("Account Balance: $" + acc1.getBalance());
    
            acc1.withdraw(24);
    
            System.out.println("Account Name: " + acc1.getName());
            System.out.println("Account Number: " + acc1.getAcctNum());
            System.out.println("Account Type: " + acc1.getAccType());
            System.out.println("Account Balance: $" + acc1.getBalance());
    
            acc1.withdraw(100);
    
            System.out.println("Account Name: " + acc1.getName());
            System.out.println("Account Number: " + acc1.getAcctNum());
            System.out.println("Account Type: " + acc1.getAccType());
            System.out.println("Account Balance: $" + acc1.getBalance());
    
        }
    The first withdraw works and displays properly but then after I withdraw 100 is just says their is still 75 on the account, whats the problem here?
    Once again thank you guys for the help
    Last edited by dmp5658; 09-15-2016 at 03:51 AM.

Page 1 of 2 12 LastLast

Similar Threads

  1. Java program using Bank Class
    By haritha in forum New To Java
    Replies: 4
    Last Post: 02-02-2016, 09:52 AM
  2. Replies: 1
    Last Post: 06-23-2014, 02:31 PM
  3. A simple bank program as homework
    By jackandjill in forum New To Java
    Replies: 4
    Last Post: 08-21-2012, 10:57 AM
  4. Bank program difficulties
    By LifeElixer in forum New To Java
    Replies: 8
    Last Post: 10-21-2011, 04:42 AM
  5. basic bank account
    By captain_turkiye in forum New To Java
    Replies: 5
    Last Post: 10-16-2011, 05:15 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
  •