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"
Code 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"
Code 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
Code Java:
--------------------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.
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)