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 6 of 6

Thread: Bank Account HELP!!!! PLEASE.

  1. #1
    Junior Member
    Join Date
    Sep 2011
    Posts
    10
    My Mood
    Amused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Bank Account HELP!!!! PLEASE.

    Okay, so basically I am an idiot and this is my first programming class. I am completely stuck on this program and I have been staring and messing with it for 4 days and cannot get it too work. For some reason I cannot get the variable to return. Someone please help, I am desperate.

    import javax.swing.*;
     
    public class Program4
    {
        // Class Variables.
        public static String firstName = "";
        public static String lastName = "";
        public static double dollars = 0.0;
     
        public static boolean isOpened = false;
        public static boolean isOverdrawn = false;
     
        // Replace "CIS Faculty" with your name.
        private final static String TITLE_BAR = "Program 4 (Me)";
     
        // Class Methods
        // Add your methods below here.
        // You should leave the main method below ALONE!!
        public static void main(String[] args)
        {
     
            showAccount(); // Will show error message about account not open
            // and will then continue.
     
            // Open new account. Give error message if it fails!
            if (!openAccount("Bill", "Smith", 100.50))
            {
                reportErrorAndBomb("Coding error 1. Open account failed on a new account!");
            }
            showAccount();
     
            // Check that accountOwner works correctly - bomb if not.
            if (!accountOwner().equals("Bill Smith"))
            {
                reportErrorAndBomb("Coding error 2. Call to accountOwner failed.");
            }
            if (balance() != 100.50) // Verify balance is correct!
            {
                reportErrorAndBomb("Coding error 3. Balance is wrong!");
            }
     
            // Confirm that I cannot reopen it!
            if (openAccount("Bogus", "Try", 55.00))
            {
                reportErrorAndBomb("Coding error 4. You allowed an account "
                        + "to be re-opened!");
            }
     
            deposit(50.00);
            showAccount();
            if (balance() != 150.50)
            {
                reportErrorAndBomb("Coding error 5. Balance is wrong!");
            }
     
            if (isNowOverdrawn())
            {
                reportErrorAndBomb("Coding error 6. Reports overdrawn when it should not.");
            }
     
            // Confirm correct workings of approveCheckFor method.
            if (approveCheckFor(150.51))
            {
                reportErrorAndBomb("Coding error 7. Approved a check for too much.");
            }
     
            if (!approveCheckFor(150.50))
            {
                reportErrorAndBomb("Coding error 8. Failed to approve a check "
                        + "for a good amount!");
            }
     
            withdraw(25.00);
            if (balance() != 125.50)
            {
                reportErrorAndBomb("Coding error 9. Balance is wrong!");
            }
     
            withdraw(125.75);
            if (balance() != -0.25)
            {
                reportErrorAndBomb("Coding error 10. Balance is wrong!");
            }
     
            showAccount(); // Should show a deficit of 25 cents.
            // and that account is now overdrawn.
     
            if (!isNowOverdrawn())
            {
                reportErrorAndBomb("Coding error 11. Should respond as overdrawn now.");
            }
     
            // Well... if you made no calls above to reportErrorAndBomb it might not
            // be working... so let us end the program with its use.
            reportErrorAndBomb("No Errors reported after testing all methods. "
                    + "\nThis tests reportErrorAndBomb. \nTesting complete with no errors!");
     
        } // main
     
        private static void withdraw(double cash)
        {
            if (dollars >= cash)
                dollars -= cash;
            else
                ;
        }
     
        private static boolean openAccount(String name, String name2,
                double funds)
        {   
            if (firstName.equals(name) & (lastName.equals(name2)))
            {
                return true;
            } 
            if (dollars >= 0 && !isOpened)
            {
                return true;
            }
            else
                return false;
        }
     
        private static boolean approveCheckFor(double check)
        {
            if (dollars >= check)
                return true;
            else
                return false;
        }
     
        private static boolean isNowOverdrawn()
        {
            if (dollars < 0.0);        
            return isOverdrawn;
     
     
        }
     
        private static void deposit(double amount)
        {
            dollars += amount;
     
        }
     
        private static double balance()
        {
            return dollars;
        }
     
        private static void reportErrorAndBomb(String message)
        {
            JOptionPane.showMessageDialog(null, message, TITLE_BAR,
                    JOptionPane.ERROR_MESSAGE);
            System.exit(0);
        }
     
        private static String accountOwner()
        {
            return  firstName + lastName;
        }
     
        private static void showAccount()
        {
     
            boolean accountOwner = true;
            String.format("%.2f", dollars);
            if (!isOpened && !accountOwner)
                JOptionPane.showMessageDialog(null, "Account Owner: " + firstName
                        + lastName + "\n" + "Account Balance: " + dollars + "\n"
                        + "Account Overdrawn: " + isOverdrawn);
            else
                JOptionPane.showMessageDialog(null,
                        "You have attempted to display an accont which is not "
                                + "opened yet. ", TITLE_BAR,
                        JOptionPane.ERROR_MESSAGE);
     
        }
     
    } // Program4
    Last edited by metaleddie13; October 12th, 2011 at 08:02 PM.


  2. #2
    Member
    Join Date
    Sep 2011
    Posts
    40
    My Mood
    Inspired
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default Re: Bank Account HELP!!!! PLEASE.

    Could you please use code tags? Like
    [ code]
    code here, with out the spaces
    [/ code]
    this is what it will come out like
    CODE HERE

    But on topic: What variable are you trying to return?

  3. #3
    Junior Member
    Join Date
    Sep 2011
    Posts
    10
    My Mood
    Amused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Bank Account HELP!!!! PLEASE.

    Sorry, like I said I'm new and dumb. I can't get the program passed the openAccount method. It hangs up and will not return the two strings and double. I have messed with it for days.

  4. #4
    Junior Member
    Join Date
    Sep 2011
    Posts
    10
    My Mood
    Amused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Bank Account HELP!!!! PLEASE.

    import javax.swing.*;
     
    public class Program4
    {
    // Class Variables.
    public static String firstName = "";
    public static String lastName = "";
    public static double dollars = 0.0;
     
    public static boolean isOpened = false;
    public static boolean isOverdrawn = false;
     
    // Replace "CIS Faculty" with your name.
    private final static String TITLE_BAR = "Program 4 (Me)";
     
    // Class Methods
    // Add your methods below here.
    // You should leave the main method below ALONE!!
    public static void main(String[] args)
    {
     
    showAccount(); // Will show error message about account not open
    // and will then continue.
     
    // Open new account. Give error message if it fails!
    if (!openAccount("Bill", "Smith", 100.50))
    {
    reportErrorAndBomb("Coding error 1. Open account failed on a new account!");
    }
    showAccount();
     
    // Check that accountOwner works correctly - bomb if not.
    if (!accountOwner().equals("Bill Smith"))
    {
    reportErrorAndBomb("Coding error 2. Call to accountOwner failed.");
    }
    if (balance() != 100.50) // Verify balance is correct!
    {
    reportErrorAndBomb("Coding error 3. Balance is wrong!");
    }
     
    // Confirm that I cannot reopen it!
    if (openAccount("Bogus", "Try", 55.00))
    {
    reportErrorAndBomb("Coding error 4. You allowed an account "
    + "to be re-opened!");
    }
     
    deposit(50.00);
    showAccount();
    if (balance() != 150.50)
    {
    reportErrorAndBomb("Coding error 5. Balance is wrong!");
    }
     
    if (isNowOverdrawn())
    {
    reportErrorAndBomb("Coding error 6. Reports overdrawn when it should not.");
    }
     
    // Confirm correct workings of approveCheckFor method.
    if (approveCheckFor(150.51))
    {
    reportErrorAndBomb("Coding error 7. Approved a check for too much.");
    }
     
    if (!approveCheckFor(150.50))
    {
    reportErrorAndBomb("Coding error 8. Failed to approve a check "
    + "for a good amount!");
    }
     
    withdraw(25.00);
    if (balance() != 125.50)
    {
    reportErrorAndBomb("Coding error 9. Balance is wrong!");
    }
     
    withdraw(125.75);
    if (balance() != -0.25)
    {
    reportErrorAndBomb("Coding error 10. Balance is wrong!");
    }
     
    showAccount(); // Should show a deficit of 25 cents.
    // and that account is now overdrawn.
     
    if (!isNowOverdrawn())
    {
    reportErrorAndBomb("Coding error 11. Should respond as overdrawn now.");
    }
     
    // Well... if you made no calls above to reportErrorAndBomb it might not
    // be working... so let us end the program with its use.
    reportErrorAndBomb("No Errors reported after testing all methods. "
    + "\nThis tests reportErrorAndBomb. \nTesting complete with no errors!");
     
    } // main
     
    private static void withdraw(double cash)
    {
    if (dollars >= cash)
    dollars -= cash;
    else
    ;
    }
     
    private static boolean openAccount(String name, String name2,
    double funds)
    {
    if (firstName.equals(name) & (lastName.equals(name2)))
    {
    return true;
    }
    if (dollars >= 0 && !isOpened)
    {
    return true;
    }
    else
    return false;
    }
     
    private static boolean approveCheckFor(double check)
    {
    if (dollars >= check)
    return true;
    else
    return false;
    }
     
    private static boolean isNowOverdrawn()
    {
    if (dollars < 0.0);
    return isOverdrawn;
     
     
    }
     
    private static void deposit(double amount)
    {
    dollars += amount;
     
    }
     
    private static double balance()
    {
    return dollars;
    }
     
    private static void reportErrorAndBomb(String message)
    {
    JOptionPane.showMessageDialog(null, message, TITLE_BAR,
    JOptionPane.ERROR_MESSAGE);
    System.exit(0);
    }
     
    private static String accountOwner()
    {
    return firstName + lastName;
    }
     
    private static void showAccount()
    {
     
    boolean accountOwner = true;
    String.format("%.2f", dollars);
    if (!isOpened && !accountOwner)
    JOptionPane.showMessageDialog(null, "Account Owner: " + firstName
    + lastName + "\n" + "Account Balance: " + dollars + "\n"
    + "Account Overdrawn: " + isOverdrawn);
    else
    JOptionPane.showMessageDialog(null,
    "You have attempted to display an accont which is not "
    + "opened yet. ", TITLE_BAR,
    JOptionPane.ERROR_MESSAGE);
     
    }
     
    } // Program4

  5. #5
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Bank Account HELP!!!! PLEASE.

    so basically I am an idiot...
    That's a great attitude to have. I recommend reading the following, which might help you formulate a question that can be answered faster

    http://www.javaprogrammingforums.com...-get-help.html

    ...and do not duplicate threads. I've deleted your other thread.

  6. #6
    Member
    Join Date
    Sep 2011
    Posts
    40
    My Mood
    Inspired
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default Re: Bank Account HELP!!!! PLEASE.

    There is much wrong with this code from what I can see, use an IDE, such as eclipse or netbeans.

Similar Threads

  1. help with my bank account program
    By captain_turkiye in forum Object Oriented Programming
    Replies: 3
    Last Post: October 14th, 2011, 10:33 AM
  2. Bank Account Program.
    By Punky0214 in forum What's Wrong With My Code?
    Replies: 10
    Last Post: November 17th, 2010, 10:42 PM
  3. Please help - Bank account application
    By brandonssss in forum What's Wrong With My Code?
    Replies: 3
    Last Post: May 2nd, 2010, 03:10 PM
  4. Bank account GUI using swing
    By AlanM595 in forum AWT / Java Swing
    Replies: 5
    Last Post: April 2nd, 2009, 04:39 AM