• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

Making a small Bank Application

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Rancher
Posts: 4504
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
See answers on DevX forum
 
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 657
Spring VI Editor Clojure
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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

Books:
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
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
> 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks a bunch guys!.I will start and let you know how it goes.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic