In: Other
Create a Java program which includes the following:
Uses a random value as well as manipulates string and character objects in order to make an SS# (xxx-xx-xxxx).
First 3 Numbers: Create a three digit random integer named FirstThree in the range of 100- 999. (10 Points)
Second 2 Numbers: Create a two digit number named SecondTwo by using FirstThree as follows: (10 Points)
If FirstThree is 550 or less then create a 2 digit string using the name StringFirstThree from the first 2 digits of FirstThree otherwise create a 2 digit string named StringFirstThree using the last 2 digits of FirstThree.
Last 4 Numbers: Use the user’s name to generate a four place number string as follows: (10 Points)
Ask the user to enter their first name. Change their input to uppercase and find the length named FirstNameLength. If the length is less than 10 then add a 0 in front of the number and call it FirstLastTwo.
Ask the user for their last name. Change their input to uppercase and find the length named LastNameLength. If the length is less than 10, then add a 0 after the number and call it SecondLastTwo.
Combine FirstLastTwo and SecondLastTwo into a string named LastFour.
SSN: Create a string named YourSSN that combines StringFirstThree, SecondTwo and
LastFour with dashes where the output is like this 123-45-9884. (10 Points)
Output: Tell the user their new SS number. (10 Points)
import java.util.Scanner;
//TestBlock.java
public class TestBlock {
public static void main(String[] args) {
//Scanner Used to get the input from user
Scanner scan = new Scanner(System.in);
//Using Math.random to calculate first three numbers
int rand = (int)(Math.random() * (999 - 100 + 1) + 100);
Integer firstThree = rand % 1000;
Integer secondTwo = 0;
if(firstThree<=550) {
secondTwo= firstThree/10;
}
else {
secondTwo= firstThree%100;
}
String second = secondTwo.toString();
if(secondTwo<10) {
second = "0"+second;
}
//Getting the first name and Last name to calculate last 4 numbers
System.out.print("Enter the First Name: ");
String firstName = scan.nextLine();
Integer len = firstName.length();
String firstLastTwo = len.toString();
if(len < 10) {
firstLastTwo = "0"+firstLastTwo;
}
System.out.print("Enter the Last Name: ");
String lastName = scan.nextLine();
len = lastName.length();
String secondLastTwo = len.toString();
if(len < 10) {
secondLastTwo = secondLastTwo + "0";
}
//Printing out the SSN
String ssn = firstThree.toString()+"-"+second+"-"+firstLastTwo+secondLastTwo;
System.out.println("Your SSN: "+ssn);
scan.close();
}
}