sunnny
10-15-2005, 01:50 AM
Hi,
I am trying to create a Account Number class with a createAccountNumber method. A unique account number is created everytime the method runs. The account number must adhere by these conditions to make sure it is unique.
1). All account numbers should be 6 digits long.
2) The first digit cannot be zero,
3) (first_digit +last_digit )%10 should be zero.
I don't know how to fulfill all the requirements and my code is not working. If someone could take a look and guide me how to do this it will be really, really helpful :D. Here is my code:
public class AccountNumberMaker{
private static int nextAvailableAccountNumber = 100009;
private int accountNumber;
public int nextAccountNumber(){
String stringNextAvailableAccountNumber = Integer.toString (nextAvailableAccountNumber);
int first_digit = nextAvailableAccountNumber / 100000;
int last_digit= nextAvailableAccountNumber % 100000;
while(true){
if(stringNextAvailableAccountNumber.length() == 6){
if((first_digit +last_digit )%10 == 0){
return nextAvailableAccountNumber;
}
}
nextAvailableAccountNumber++;
}
}
} //end class AccountNumberMaker
Thanks!!!!!!!
Sunny
I am trying to create a Account Number class with a createAccountNumber method. A unique account number is created everytime the method runs. The account number must adhere by these conditions to make sure it is unique.
1). All account numbers should be 6 digits long.
2) The first digit cannot be zero,
3) (first_digit +last_digit )%10 should be zero.
I don't know how to fulfill all the requirements and my code is not working. If someone could take a look and guide me how to do this it will be really, really helpful :D. Here is my code:
public class AccountNumberMaker{
private static int nextAvailableAccountNumber = 100009;
private int accountNumber;
public int nextAccountNumber(){
String stringNextAvailableAccountNumber = Integer.toString (nextAvailableAccountNumber);
int first_digit = nextAvailableAccountNumber / 100000;
int last_digit= nextAvailableAccountNumber % 100000;
while(true){
if(stringNextAvailableAccountNumber.length() == 6){
if((first_digit +last_digit )%10 == 0){
return nextAvailableAccountNumber;
}
}
nextAvailableAccountNumber++;
}
}
} //end class AccountNumberMaker
Thanks!!!!!!!
Sunny