i'm fairly new to programming (only started this year) and i need some help on something that i'm making. the task is to write a Java program to ask the user for an ID number (RSA) and to validate the ID number and tell the user if the number they entered was valid or not. The rules for valid ID numbers are:
* Calculate total A by adding the figures in the odd positions i.e. the first, third, fifth, seventh, ninth and eleventh digits.
* Calculate total B by taking the even figures of the number as a whole number, and then multiplying that number by 2, and then add the individual figures together.
* Calculate total C by adding total A to total B. The control-figure can now be determined by subtracting the ones column from figure C from 10. Where the total C is a multiple of 10, the control figure will be 0.
i wrote te following code:
public class IDNumberVerification
{
public static void main (String [] args)
{
String idNumber;
idNumber = JOptionPane.showInputDialog("Enter an ID number");
int totA = 0;
totA = totA + idNumber.charAt(0) - (int)'0';
totA = totA + idNumber.charAt(2) - (int)'0';
totA = totA + idNumber.charAt(4) - (int)'0';
totA = totA + idNumber.charAt(6) - (int)'0';
totA = totA + idNumber.charAt(8) - (int)'0';
totA = totA + idNumber.charAt(10) - (int)'0';
int totB = 0;
totB = idNumber.charAt(1) - (int)'0';
totB = idNumber.charAt(3) - (int)'0';
totB = idNumber.charAt(5) - (int)'0';
totB = idNumber.charAt(7) - (int)'0';
totB = idNumber.charAt(9) - (int)'0';
totB = idNumber.charAt(11) - (int)'0';
}
}
now for totB i want to display those numbers as a whole number as in instruction number 2. example ID I'm using: 9301285276088
* Calculate total A by adding the figures in the odd positions i.e. the first, third, fifth, seventh, ninth and eleventh digits.
* Calculate total B by taking the even figures of the number as a whole number, and then multiplying that number by 2, and then add the individual figures together.
* Calculate total C by adding total A to total B. The control-figure can now be determined by subtracting the ones column from figure C from 10. Where the total C is a multiple of 10, the control figure will be 0.
i wrote te following code:
public class IDNumberVerification
{
public static void main (String [] args)
{
String idNumber;
idNumber = JOptionPane.showInputDialog("Enter an ID number");
int totA = 0;
totA = totA + idNumber.charAt(0) - (int)'0';
totA = totA + idNumber.charAt(2) - (int)'0';
totA = totA + idNumber.charAt(4) - (int)'0';
totA = totA + idNumber.charAt(6) - (int)'0';
totA = totA + idNumber.charAt(8) - (int)'0';
totA = totA + idNumber.charAt(10) - (int)'0';
int totB = 0;
totB = idNumber.charAt(1) - (int)'0';
totB = idNumber.charAt(3) - (int)'0';
totB = idNumber.charAt(5) - (int)'0';
totB = idNumber.charAt(7) - (int)'0';
totB = idNumber.charAt(9) - (int)'0';
totB = idNumber.charAt(11) - (int)'0';
}
}
now for totB i want to display those numbers as a whole number as in instruction number 2. example ID I'm using: 9301285276088