ENUNCIADO:
The algorithm to obtain the letter of the NIF corresponding to a DNI consists of the following steps:
- Obtain the rest of the entire division of the DNI by 23.
- The letter is the one in the indexed position of the following string, which corresponds the value of the previous waste: "TRWAGMYFPDXBNJZSQVHLCKE" example: the remainder of divide 22334455 between 23 is 6 and in position 6 of the previous chain is found the letter Y'. (The positions of the text strings start at 0).
- Make a program that asks to enter DNI numbers until the user ends by entering a specific character (f | F).
- DNI s must be stored in an array that starts with size 1 and must resize, increasing it in one position each time the user enters a new DNI.
- The program must show the NIFs with their letters.
ENTRY OF DNI s:
22334455
45678965
12123256
45678964
45678987
12123233
DEPARTURE OF NIF s:
22334455Y
45678965E
12123256W
45678964K
45678987K
12123233W
After the attached statement what I have done: link
public static void main(String[] args) {
Scanner lector = new Scanner(System.in);
String[] letras = {"T", "R", "W", "A", "G", "M", "Y", "F", "P", "D", "X", "B", "N", "J", "Z", "S", "Q", "V", "H", "L", "C", "K", "E"};
int[] valors = new int[5];
int ocupacio = 0, i, x;
int posicion;
do {
System.out.println("Introduce numeros de DNI");
for (i = 0; i < valors.length; i++) {
if (lector.hasNextInt()) {
valors[i] = lector.nextInt();
} else if (lector.hasNext("fi")) {
break;
} else {
System.out.println("Dada Incorrecta");
lector.nextLine();
i--;
}
}
for (x = 0; x < letras.length; x++) {
letras[x] = lector.next();
ocupacio = i;
posicion = x % 23;
for (int j = 0; j < ocupacio; j++) {
System.out.println(valors[j]);
System.out.println("NIF: " + valors[j] + "-"+ letras[posicion]);
}
}
} while (!lector.hasNext("fi"));
}
}
I only have the last part that is to resize the array so that it shows me the letter next to the DNI that I enter and also not put together each letter with each DNI, I know that something has to be done with a counter but I do not know how do it and the truth is that I'm desperate, I hope you can give me a hand, many thanks from my heart.