File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes need help with code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "need help with code" Watch "need help with code" New topic

need help with code

christopher pam

Joined: Jan 12, 2005
Posts: 5
import java.util.Scanner;

public class Account
private double balance;
private double withdrawal;

public Account(double initialBalance)
if(initialBalance > 0.0)
balance = initialBalance;

if(withdrawal < 25000.00)
withdrawal = balance;
System.out.print("Debit amount exceeded account balance");
public void debit(double withdrawal)
balance = balance - withdrawal;

public void credit(double amount)
balance = balance + amount;

public double getBalance()
return balance;

public static void main(String args[])
Account account = new Account(25000.00);

Scanner input = new Scanner(;
double depositAmount;
double withdrawalAmount;

System.out.printf("You've got $%.2f in your account\n",account.getBalance());

System.out.print("Enter deposit amount");
depositAmount = input.nextDouble();
System.out.printf("nAdding %.2f to the account concerned\n\n",depositAmount);;
System.out.printf("You've got $%.2f in your account\n",account.getBalance());

System.out.print("Enter withdrawal amount");
withdrawalAmount = input.nextDouble();
System.out.printf("nDeducting $%.2f from the account concerned\n\n",withdrawalAmount);
System.out.printf("You've got $%.2f in your account\n",account.getBalance());

the above code is supposed to give me ma account balance and prompt me to enter a deposit amount which it'll add up to the initial balance and afterwards prompt me to enter withdrawal amount,now this is where ma problem tryin to ensure that the debit amount does not exceed the account's balance,if it does the balance is to be left unchanged and printing a message indicating "Debit amount exceeds account balance".instead it keeps leaving the account with a negative balance.what do i do?
fred rosenberger
lowercase baba

Joined: Oct 02, 2003
Posts: 11955

Please use the code tags around your source code. there are those little "instand ubb code" buttons - one is labeld "code". by using this, and pasting your code between the tags, the formatting is preserved, making what you have MUCH easier to read.

Now, take a look at this code:

what is it doing?
[ March 19, 2007: Message edited by: Fred Rosenberger ]

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
I agree. Here's the link:
subject: need help with code
jQuery in Action, 3rd edition