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 Making a small Bank Application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Making a small Bank Application" Watch "Making a small Bank Application" New topic

Making a small Bank Application

daisy polly

Joined: Oct 10, 2005
Posts: 10

I am making a small Bank program and in that I am making a class called AccountNumberMaker which looks something like this:
public class AccountNumberMaker{

private int nextAvailableAccountNumber = 100009;

public int nextAccountNumber() {

I need to know how to make all the accounts numbers 6 digits long not more and not less than 6 also the first digit should not be be zero and also (first_digit +last_digit )%10 should be zero. How to do this in Java I am so confused. Any Help will be appreciated.

Norm Radder
Ranch Hand

Joined: Aug 10, 2005
Posts: 694
See answers on DevX forum
Kenneth Albertson
Ranch Hand

Joined: Sep 18, 2005
Posts: 59
Just what part of the problem are you having trouble with? All you need to do is to generate a sequence of numbers:

100009, 100019, 100029 ... 999981, 999991

It's just a simple sequence, in order. No random number generators are required. Your declaration of nextAvailableAccountNumber is fine. All you need to do is finish nextAccountNumber(). The simple approach would be to just keep adding 1 to nextAvailableAccountNumber until getting to the next acceptable number (or exceeding the upper limit).

An alternative approach would be to make use of the obvious relationship between the first and last digits, which you should be able to see in the sequence listing above. Most of the time the next number is the current number + 10. The only time this changes is when the first digit is about to change, in which case you use current number + 9.

Does that give you enough guidance to make some progress? Show us your attempt at nextAccountNumber(), and tell us what happens when you try to compile and run it.
daisy polly

Joined: Oct 10, 2005
Posts: 10
Thanks for the suggestions. I have no idead how to start with the code could you please give me a little help how the structure of the code will be. Thanks again.

Steve Morrow
Ranch Hand

Joined: May 22, 2003
Posts: 657

I have no idead how to start with the code

There are plenty of resources to get you started down the road to programming in Java. Here are several:

The Java� Tutorial - A practical guide for programmers
The Java� Tutorial - Trail: Learning the Java Language
New to Java Center
Java Programming Notes - Fred Swartz
How To Think Like A Computer Scientist
Introduction to Computer Science using Java
The Java Developers Almanac 1.4

Object-Oriented Programming Concepts
Object-oriented language basics
Don't Fear the OOP

The Java Programming Language - 4th Edition
Head First Java, by Bert Bates and Kathy Sierra
Thinking in Java (Free online), by Bruce Eckel
Core Java, by Cay Horstmann and Gary Cornell
Effective Java, by Joshua Bloch
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> a little help how the structure of the code will be.

have a look at the sequence in Kym's post

the account number is a string, made up of 2 parts 'joined'
1) int nextNumber = 10000;
2) int checkNumber = 10 - nextNumber/10000;
3) String accountNumber = String.valueOf(nextNumber)+checkNumber;
when accountNumber is generated, increase nextNumber by 1 (nextNumber++)

so, in this example
nextNumber = 10000
checkNumber = 10 - nextNumber/10000 = 10 - 1 = 9
accountNumber = "10000"+9 = "100009"

when nextNumber clicks over to 20000, checkNumber = 10 - 2 = 8,
then accountNumber = "20000"+8 = "200008"

any clearer?
Kenneth Albertson
Ranch Hand

Joined: Sep 18, 2005
Posts: 59
Michael has given you some more help on the logic needed for the nextAccountNumber method. The first thing that you will need is a test harness. You could use something like this:The next step is for you to start coding up the AccountNumberMaker class and nextAccountNumber() method. Let us know how you go.
daisy polly

Joined: Oct 10, 2005
Posts: 10
thanks a bunch guys!.I will start and let you know how it goes.
I agree. Here's the link:
subject: Making a small Bank Application
It's not a secret anymore!