Results 1 to 5 of 5
  1. #1
    Interista is offline Member
    Join Date
    Oct 2011
    Posts
    24
    Rep Power
    0

    Default Simple Bank Account Program - Completely Confused

    Our lecturer has just introduced us to Defining and Implementing Classes.

    He gave us a Bank Account program. He asked us to set up a bank account of 5000.00 which would then have 200.00 withdrawn and to print the result with JOptionPane.

    The problem is I am COMPLETELY CONFUSED

    I can load up the pdf files he gave us the assignment on but it will be messy as pdf doesn't generally copy and paste too well.

    Java Code:
    import javax.swing.JOptionPane;
    public class FixedStaringBalanceBankAccount{
    
    	BankAccount = myFirstAccount;
    	public void balance(5000.00d)
    	public void withdraw(200.00d)
    	{
    	myFirstAccount=balance-withdraw
    	}
    		
    	JOptionPane.showMessageDialog(null, "My first account contains " + myFirstAccount);
    
    }
    The code I've worked on is that above, even to me it doesn't look right but its putting out so many errors I think I've just misunderstood the question.

    Java Code:
    /**
    A bank account has a balance that can be changed by 
    deposits and withdrawals.
    */
    class BankAccount{  
    
    private double balance; 
    /**
       Deposits money into the bank account.
       @param amount the amount to deposit
    */
    public void deposit(double amount) {  
       balance = balance + amount;
    }
    
    /**
       Withdraws money from the bank account.
       @param amount the amount to withdraw
    */ 
    public void withdraw(double amount) {  
       balance = balance - amount;
    }
    
    /**
       Gets the current balance of the bank account.
       @return the current balance
    */
    public double getBalance(){  
       return balance; 
    }
    
    /**
       Constructs a bank account with a zero balance.
    */
    public BankAccount(){  
       balance = 0;
    }
    
    /**
       Constructs a bank account with a given balance.
       @param initialBalance the initial balance
    */ 
    public BankAccount(double initialBalance){  
       balance = initialBalance;
    }
    
    }
    This above is his Bank Account code which when it compiles and runs it puts out an error, is that because he's made an error or is it because our file is supposed to fix the error.

    Please help, this is so confusing.

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,725
    Blog Entries
    7
    Rep Power
    21

    Default Re: Simple Bank Account Program - Completely Confused

    Those first thirteen lines are so full of errors of all sorts, I don't even know where to start, so I don't even try. Have you read a Java textbook and read some simple examples?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    SRaith is offline Member
    Join Date
    Oct 2011
    Posts
    14
    Rep Power
    0

    Default Re: Simple Bank Account Program - Completely Confused

    The BankAccount class just works fine.
    And your main should look something like this:

    Java Code:
    import javax.swing.JOptionPane;
    
    
    public class FixedStaringBalanceBankAccount
    {
    	public static void main(String[] args)
    	{
    		BankAccount myAccount = new BankAccount(5000);
    		myAccount.withdraw(200);
    		JOptionPane.showMessageDialog(null, "Blah blah Text: " + myAccount.getBalance());
    	}
    }

  4. #4
    Interista is offline Member
    Join Date
    Oct 2011
    Posts
    24
    Rep Power
    0

    Default Re: Simple Bank Account Program - Completely Confused

    Quote Originally Posted by SRaith View Post
    The BankAccount class just works fine.
    And your main should look something like this:

    Java Code:
    import javax.swing.JOptionPane;
    
    
    public class FixedStaringBalanceBankAccount
    {
    	public static void main(String[] args)
    	{
    		BankAccount myAccount = new BankAccount(5000);
    		myAccount.withdraw(200);
    		JOptionPane.showMessageDialog(null, "Blah blah Text: " + myAccount.getBalance());
    	}
    }
    Thanks a million!

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Simple Bank Account Program - Completely Confused

    Quote Originally Posted by SRaith View Post
    The BankAccount class just works fine.
    And your main should look something like this:

    Java Code:
    import javax.swing.JOptionPane;
    
    
    public class FixedStaringBalanceBankAccount
    {
    	public static void main(String[] args)
    	{
    		BankAccount myAccount = new BankAccount(5000);
    		myAccount.withdraw(200);
    		JOptionPane.showMessageDialog(null, "Blah blah Text: " + myAccount.getBalance());
    	}
    }
    My experience in this and other forums has been that it's easy to spoon feed someone answer, much easier than taking the time and effort to try to get them to understand a concept and learn how to correct their code themselves, but usually they learn close to nothing from your effort, other than how to beg for code. Please try to limit your spoon feeding in the future. Instead try to explain the concepts, answer their direct questions, and help lead them towards finding an answer.

Similar Threads

  1. basic bank account
    By captain_turkiye in forum New To Java
    Replies: 5
    Last Post: 10-16-2011, 06:15 PM
  2. HELP!!! Completely confused on how to fix this program!!!
    By BeginnerJava in forum New To Java
    Replies: 17
    Last Post: 06-13-2011, 12:59 AM
  3. Bank Account Project
    By Haal in forum New To Java
    Replies: 0
    Last Post: 03-20-2011, 08:30 PM
  4. how to make to classes in the bank account program
    By buzzing in forum New To Java
    Replies: 3
    Last Post: 11-02-2010, 05:02 AM
  5. Bank Account
    By HPcompaq256 in forum New To Java
    Replies: 11
    Last Post: 02-26-2010, 10:05 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
  •