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

Thread: I need help with a sort of banking program

  1. #1
    Junior Member
    Join Date
    Sep 2012
    Posts
    10
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default I need help with a sort of banking program

    Hello, I've been stuck trying to get this to work but I've had no such luck and I was hoping you could help. What I'm trying to do is to make method called debit that will withdraw money from the account and to print a message if it exceeds it. Thanks.


    "Account.java"
    public class Account {
     
        private double balance;
     
        public Account( double initialBalance )
        {
        	if ( initialBalance > 0.0 )
        		balance = initialBalance;
        }
     
        public void credit( double amount )
        {
        	balance = balance + amount;
        } 
        public void debit( String[] args );
     
        public double getBalance()
        {
        	return balance;
        } 
     
    }

    "AccountTest.java"
    public class AccountTest 
    {
        public static void main( String args[] ) 
        {
        	Account account1 = new Account( 50.00 );
        	Account account2 = new Account( -7.53 );
     
        	System.out.printf( "account1 balance: $%.2f\n",
        		account1.getBalance() );
        	System.out.printf( "account2 balance: $%.2f\n\n",
        		account2.getBalance() );
        	Scanner input = new Scanner( System.in );
        	double withdrawalAmount;
     
        	System.out.print( "Enter withdrawal amount for account1: " );
        	withdrawalAmount = input.nextDouble();
        	System.out.printf( "\nsubtracting %.2f from account1 balance\n",
        		withdrawalAmount );
        	account2.credit( withdrawalAmount );
     
        	System.out.printf( "account1 balance: $%.2f\n",
        		account1.getBalance() );
        	System.out.printf( "account2 balance: $%.2f\n",
        		account2.getBalance() );
        }
     
     
    }

    Current Syntax errors
    --------------------Configuration: <Default>--------------------
    C:\Users\Cam\Documents\Account.java:24: error: missing method body, or declare abstract
        public void debit( String[] args );
                    ^
    1 error
     
    Process completed.


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,168
    My Mood
    Hungover
    Thanks
    141
    Thanked 598 Times in 513 Posts

    Default Re: I need help with a sort of banking program

    The error message says it all: methods need a body, unless the class is abstract. Where is your debit() method's body?

    Recommended reading: Defining Methods (The Java™ Tutorials > Learning the Java Language > Classes and Objects)
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Need some help with my Banking program
    By bankston13 in forum What's Wrong With My Code?
    Replies: 7
    Last Post: September 17th, 2012, 09:04 PM
  2. How to call a C sort function to sort a Java Array.
    By Dwere13 in forum Java Native Interface
    Replies: 22
    Last Post: July 12th, 2012, 04:44 PM
  3. banking system
    By preeti in forum Java Theory & Questions
    Replies: 3
    Last Post: August 11th, 2011, 01:25 PM
  4. Banking Application
    By mbouster in forum Object Oriented Programming
    Replies: 2
    Last Post: January 9th, 2011, 10:23 AM
  5. bubble sort and selection sort on strings
    By Sir Saula in forum What's Wrong With My Code?
    Replies: 5
    Last Post: July 3rd, 2010, 09:44 AM