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

Thread: BankAccount assignment problem

  1. #1
    Junior Member
    Join Date
    Oct 2011
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default BankAccount assignment problem

    Hi everyone,

    I have been given an assignment to create a file called FixedStartingBalanceBankAccount. I have also been given a BankAccount class file(attached).

    My assignment is to create a BankAccount object in a variable called myFirstAccount with an initial balance of 5000.

    After this I have to withdraw 200 from the account and display the balance after withdrawal using JOptionPane messageDialog.

    This is the code I have for setting up account with initial balance and making withdrawal. I am not sure if this is the way to do it.

    import javax.swing.JOptionPane;
    public class FixedStartingBalanceBankAccount
    {

    public class BankAccount
    {

    //Constructors
    public BankAccount()
    {
    BankAccount myFirstAccount = new BankAccount();
    }
    public BankAccount(double initialBalance)
    {
    initialBalance = 5000;
    }
    //Methods
    public void withdraw(double amount)
    {
    amount = 200;
    }
    }
    }

    If this is correct how do i get the balance and display it using JOptionPane. Any help would be greatly appreciated as i have spent hours upon hours pulling my hair out trying to get this to work.
    Attached Files Attached Files


  2. #2
    Junior Member
    Join Date
    Oct 2011
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: BankAccount assignment problem

    I have overcome some of my confusion and come up with this;

    import javax.swing.JOptionPane;
    public class FixedStartingBankBalanceAccount

    {

    public static void main(String[] args)
    {


    double balance;
    BankAccount myFirstAccount = new BankAccount(5000);
    myFirstAccount.withdraw(200);
    System.out.println(myFirstAccount.getBalance());

    JOptionPane.showMessageDialog(null, "myFirstAccount contains:" + balance);
    }
    }
    I am still a little confused on whether I need to declare the variables such as balance or is this done in the BankAccount file??

  3. #3
    Junior Member
    Join Date
    Oct 2011
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: BankAccount assignment problem

    I have overcome some of my confusion and come up with this;

    import javax.swing.JOptionPane;
    public class FixedStartingBankBalanceAccount

    {

    public static void main(String[] args)
    {


    double balance;
    BankAccount myFirstAccount = new BankAccount(5000);
    myFirstAccount.withdraw(200);
    System.out.println(myFirstAccount.getBalance());

    JOptionPane.showMessageDialog(null, "myFirstAccount contains:" + balance);
    }
    }
    I am still a little confused on whether I need to declare the variables such as balance or is this done in the BankAccount file??

Similar Threads

  1. assignment troubles polymorphism (guide for assignment included)
    By tdawg422 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 8th, 2011, 10:01 AM
  2. Problem with code for school assignment?
    By Mellisa315 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: December 16th, 2010, 08:36 PM
  3. Assignment problem.
    By minou13 in forum Java Theory & Questions
    Replies: 1
    Last Post: November 26th, 2010, 09:51 PM
  4. Replies: 1
    Last Post: February 22nd, 2010, 07:20 AM
  5. [SOLVED] "GridLayout" problem in Java program
    By antitru5t in forum AWT / Java Swing
    Replies: 3
    Last Post: April 16th, 2009, 10:26 AM