Win a copy of The Way of the Web Tester: A Beginner's Guide to Automating Tests this week in the Testing forum!

# Making a small Bank Application

daisy polly
Greenhorn
Posts: 10
Hi,
Hi,

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() {
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.

Thanks
Daisy

Bartender
Posts: 1482
14

Kenneth Albertson
Ranch Hand
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
Greenhorn
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.

Daisy

Steve Morrow
Ranch Hand
Posts: 657

Michael Dunn
Ranch Hand
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
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
Greenhorn
Posts: 10
thanks a bunch guys!.I will start and let you know how it goes.