For Visual Basic 2012: Write a program that reads social security number and pri
ID: 3563488 • Letter: F
Question
For Visual Basic 2012: Write a program that reads social security number and print last 4 digits if first digit is either 2 or 3.
I got this far, but have no idea what to write so that only the last four numbers become visible, when only 2&3 are used...right now I can use anynumber and something will pop up. Also I am using 2 textboxes and a button. What sort of mindset should I be thinking when trying to figure out a problem of this sort. A solution to the problem would be appreciated along with an explanation of the use of language.
Public Class Form1
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim number As String
If IsNumeric(TextBox1.Text) Then
number = CStr(TextBox1.Text)
If IsNumeric(2 Or 3) Then
TextBox2.Text = 638
End If
ElseIf
TextBox2.Text = "This is wrong SS#"
End If
End Sub
End Class
Explanation / Answer
public static boolean checkSSN(String social) { boolean valid = false; // 9 digits and 2 hyphens. First three characters, 5 and 6, and 8, 9, // 10, 11 are digits // Check that the length is valid if (social.length() == 11) { valid = true; } else { valid = false; } // Check that the characters are valid // Valid as digits char index0 = social.charAt(0); char index1 = social.charAt(1); char index2 = social.charAt(2); char index4 = social.charAt(4); char index5 = social.charAt(5); char index7 = social.charAt(7); char index8 = social.charAt(8); char index9 = social.charAt(9); char index10 = social.charAt(10); // Valid as hyphen char index3 = social.charAt(3); char index6 = social.charAt(6); if (Character.isDigit(index0) && Character.isDigit(index1) && Character.isDigit(index2) && Character.isDigit(index4) && Character.isDigit(index5) && Character.isDigit(index7) && Character.isDigit(index8) && Character.isDigit(index9) && Character.isDigit(index10)) { valid = true; } else valid = false; if (index3 == '-' && index6 == '-') { valid = true; } else valid = false; return valid; }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.