Question

In: Other

Intro to Java. Creating random SSN

  1. 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).

  1. First 3 Numbers: Create a three digit random integer named FirstThree in the range of 100- 999. (10 Points)

  2. 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.

  3. 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.

  4. 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)

  5. Output: Tell the user their new SS number. (10 Points)


Solutions

Expert Solution

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();

    

  }  

  

}



Related Solutions

Time Calculator – Intro To Programming - JAVA Write a program that asks the user to...
Time Calculator – Intro To Programming - JAVA Write a program that asks the user to enter a number of seconds. • There are 60 seconds in a minute. If the number of seconds entered by the user is greater than or equal to 60, the program should display the number of minutes in that many seconds. • There are 3,600 seconds in an hour. If the number of seconds entered by the user is greater than or equal to...
This is an Intro to java question. Please provide code and pseudocode for better understanding. Problem...
This is an Intro to java question. Please provide code and pseudocode for better understanding. Problem 4: Player Move Overworld (10 points) (Game Development) You're the lead programmer for an indie game studio making a retro-style game called Zeldar. You've been tasked to implement the player movement. The game is top-down, with the overworld modeled as a 2d grid. The player's location is tracked by x,y values correlating to its row and column positions within that grid. Given the current...
This is an intro to java question. Please answer with pseudocode and code. Problem 2: RSA...
This is an intro to java question. Please answer with pseudocode and code. Problem 2: RSA Public Key (10 points) (Cyber Security) RSA is an asymmetric encryption scheme, where a public key is used to encrypt data and a different, private key decrypts that data. RSA public/private keys are generated from two prime numbers, typically very large ones. The idea behind RSA is based on the fact that its difficult to factorize very large integers. RSA public key generation is...
This is an Intro to Java Question, Please respond with code and pseudocode. Problem 3: RSA...
This is an Intro to Java Question, Please respond with code and pseudocode. Problem 3: RSA Private Key (10 points) (Cyber Security) In the RSA algorithm, encrypting and decrypting a message is done using a pair of numbers that are multiplicative inverses with respect to a carefully selected modulus. In this task, you must calculate the modular multiplicative inverse for given set of values. What is the Modular Multiplicative Inverse? In mathematics, each operation typically has an inverse. For example,...
Task Intro: Password JAVA. Write a method that checks a password. The rules for the password...
Task Intro: Password JAVA. Write a method that checks a password. The rules for the password are: - The password must be at least 10 characters. - The password can only be numbers and letters. - Password must have at least 3 numbers. Write a test class that tests the checkPassword method. Hint: You can (really should) use method from built-in String class: public boolean matches(String regex) to check that the current string matches a regular expression. For example, if...
this is my assignment for intro to java tha i could not figure out, my system...
this is my assignment for intro to java tha i could not figure out, my system just crashed wit a lot of errors. thank for your help Create a new Java class inside your project folder. The name of the class should be: TempConverter Note that this means you should have the following line at the top of your program: public class TempConverter Write a program that allows the user to convert a temperature given in degrees Celsius or Fahrenheit...
Intro to java Problem, Please provide code and Pseudocode. Not able to compile correct numbers. Problem...
Intro to java Problem, Please provide code and Pseudocode. Not able to compile correct numbers. Problem 7: Simple Calculator (10 points) (General) Calculators represent the most basic, general-purpose of computing machines. Your task is to reduce your highly capable computer down into a simple calculator. You will have to parse a given mathematical expression, and display its result. Your calculator must support addition (+), subtraction (-), multiplication (*), division (/), modulus(%), and exponentiation (**). Facts ● Mathematical expressions in the...
Intro to Java Question. Please Provide code and pseudocode for understanding. Not receiving correct results currently....
Intro to Java Question. Please Provide code and pseudocode for understanding. Not receiving correct results currently. Problem 5: Player Move Dungeon (10 points) (Game Development) You're the lead programmer at a AAA studio making a sequel to the big hit game, Zeldar 2. You've been challenged to implement player movement in dungeons. The game is top-down, with dungeons modeled as a 2d grid with walls at the edges. The player's location is tracked by x,y values correlating to its row...
(Intro/Basic) JAVA Write a small program that gets some numbers as command-line arguments and finds the...
(Intro/Basic) JAVA Write a small program that gets some numbers as command-line arguments and finds the maximum of those numbers. You can assume that the user will provide some command-line arguments when running the program (so you don’t have to worry about what to do if the user doesn’t provide any arguments -- that won’t happen). Also, you can assume that all the command line arguments will be floating-point numbers, i.e., numbers with a decimal point, like 2.95.
In Java In this lab we will creating two linked list classes: one that is a...
In Java In this lab we will creating two linked list classes: one that is a singly linked list, and another that is a doubly linked list ( This will be good practice for your next homework assignment where you will build your own string class using arrays and linked list ) . These LinkedList classes should both be generic classes. and should contain the following methods: Print Add - Adds element to the end of the linked list. IsEmpty...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT