Adeno
October 5th, 2006, 07:10 PM
Hi guys=( I'm in a little trouble=( I got sick for a whole week and we have a due mini-project soon. I really tried hard trying to figure this out for myself (and of course by asking classmates too) but everyone I approached seem to be just as lost as I am. It would be great if someone could help me=) This is what we're supposed to do:
=====================================================
You will need to store each digit of the social insurance number in a field of its own. To validate the entry you will:
1. Multiply the 2nd, 4th, 6th and 8th digit by 2.
2. If the product of any of the four multiplications result in a value greater than 9, add the two resulting digits together to yield a single-digit response. For example 6 * 2 = 12, so you would add the 1 and the 2 to get a result of 3.
3. Add these four calculated values together, along with the 1st, 3rd, 5th, and 7th digits of the original number.
4. Subtract this sum from the next highest multiple of 10.
5. The difference should be equal to the 9th digit, which is considered the check digit.
Example of validating S.I.N. 765932546
1st digit 7
2nd digit (6*2 =12 1+2=) 3
3rd digit 5
4th digit (9*2 = 18 1+8 =) 9
5th digit 3
6th digit (2*2 = 4) 4
7th digit 5
8th digit (4*2 = 8) 8
Total 44 next multiple of 10 is 50
50-44 = 6 which is the 9th digit
Therefore the S.I.N. 765932546 is Valid
**********************************
********* SIN Validation *********
**********************************
Welcome - Please enter the first number: 120406780
Second digit value multiplied by 2 4
Fourth digit value multiplied by 2 8
Sixth digit value multiplied by 2 12
Eighth digit value multiplied by 2 16
Value derived from 6th digit 3
Value derived from 8th digit 7
The total is 30
Calculated digit is 10
Check digit must be zero because calculated value is 10
The SIN 120406780 is Valid
=====================================================
So that's what we're supposed to do, and this is what I have come up with so far:
=====================================================
import java.util.Scanner;
public static class lab1
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
int sin = 0;
int num0, num1, num2, num3, num4, num5, num6, num7, num8;
int count = 0;
int second, fourth, sixth, eighth;
System.out.println("Please enter a sin number: ");
sin = input.nextInt();
count = int.length(sin);
while (count > 8 || count < 8)
{
System.out.println("Valid Input");
System.out.println("Please enter a sin number: ");
sin = input.nextInt();
}
num0 = input.next().charAt(0);
num1 = input.next().charAt(1);
num2 = input.next().charAt(2);
num3 = input.next().charAt(3);
num4 = input.next().charAt(4);
num5 = input.next().charAt(5);
num6 = input.next().charAt(6);
num7 = input.next().charAt(7);
num8 = input.next().charAt(8);
second = num2 * 2;
fourth = num4 * 2;
sixth = num6 * 2;
eighth = num8 * 2;
}
}
=====================================================
Can someone please try this? I always get an error and I'm really really stumped as to what I'm missing. I have an idea of how to do the program, just that since I'm still a beginner, I do get lost from time to time (plus the fact that I got sick and missed out on class)=(
Your help would be greatly appreciated, I really hope somebody could show me how to fix this, and tell me in detail what I'm missing=( Thanks in advance guys!
=====================================================
You will need to store each digit of the social insurance number in a field of its own. To validate the entry you will:
1. Multiply the 2nd, 4th, 6th and 8th digit by 2.
2. If the product of any of the four multiplications result in a value greater than 9, add the two resulting digits together to yield a single-digit response. For example 6 * 2 = 12, so you would add the 1 and the 2 to get a result of 3.
3. Add these four calculated values together, along with the 1st, 3rd, 5th, and 7th digits of the original number.
4. Subtract this sum from the next highest multiple of 10.
5. The difference should be equal to the 9th digit, which is considered the check digit.
Example of validating S.I.N. 765932546
1st digit 7
2nd digit (6*2 =12 1+2=) 3
3rd digit 5
4th digit (9*2 = 18 1+8 =) 9
5th digit 3
6th digit (2*2 = 4) 4
7th digit 5
8th digit (4*2 = 8) 8
Total 44 next multiple of 10 is 50
50-44 = 6 which is the 9th digit
Therefore the S.I.N. 765932546 is Valid
**********************************
********* SIN Validation *********
**********************************
Welcome - Please enter the first number: 120406780
Second digit value multiplied by 2 4
Fourth digit value multiplied by 2 8
Sixth digit value multiplied by 2 12
Eighth digit value multiplied by 2 16
Value derived from 6th digit 3
Value derived from 8th digit 7
The total is 30
Calculated digit is 10
Check digit must be zero because calculated value is 10
The SIN 120406780 is Valid
=====================================================
So that's what we're supposed to do, and this is what I have come up with so far:
=====================================================
import java.util.Scanner;
public static class lab1
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
int sin = 0;
int num0, num1, num2, num3, num4, num5, num6, num7, num8;
int count = 0;
int second, fourth, sixth, eighth;
System.out.println("Please enter a sin number: ");
sin = input.nextInt();
count = int.length(sin);
while (count > 8 || count < 8)
{
System.out.println("Valid Input");
System.out.println("Please enter a sin number: ");
sin = input.nextInt();
}
num0 = input.next().charAt(0);
num1 = input.next().charAt(1);
num2 = input.next().charAt(2);
num3 = input.next().charAt(3);
num4 = input.next().charAt(4);
num5 = input.next().charAt(5);
num6 = input.next().charAt(6);
num7 = input.next().charAt(7);
num8 = input.next().charAt(8);
second = num2 * 2;
fourth = num4 * 2;
sixth = num6 * 2;
eighth = num8 * 2;
}
}
=====================================================
Can someone please try this? I always get an error and I'm really really stumped as to what I'm missing. I have an idea of how to do the program, just that since I'm still a beginner, I do get lost from time to time (plus the fact that I got sick and missed out on class)=(
Your help would be greatly appreciated, I really hope somebody could show me how to fix this, and tell me in detail what I'm missing=( Thanks in advance guys!