1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
agasfer [191]
3 years ago
9

Write a program that will ask the user for a person’s name and social security number. The program will then check to see if the

social security number is valid. An exception will be thrown if an invalid SSN is entered. You will be creating your own exception class in this program. You will also create a driver program that will use the exception class. Within the driver program, you will include a static method that throws the exception.

Computers and Technology
1 answer:
Triss [41]3 years ago
4 0

Answer:

See explaination for the program code

Explanation:

//SocSecProcessor.java:

import java.util.Scanner;

public class SocSecProcessor

{

public static void main (String [] args)

{

Scanner keyboard = new Scanner (System.in);

String name;

String socSecNumber;

String response;

char answer = 'Y';

while (Character.toUpperCase(answer) == 'Y')

{

try

{

// Task #2 step 1 - To do:

// promote user to enter name and ssn number.

// save the input to variable name and SocSecNumber. Such as:

// System.out.print("Name? ");

// name = keyboard.nextLine();

// validate SSN number by calling isValid(socSecNumber).

// output the checking result.

System.out.print("Name?");

name = keyboard.nextLine();

System.out.print("SSN?");

socSecNumber = keyboard.nextLine();

if(isValid(socSecNumber)){

System.out.println(name + " " + socSecNumber + "is Valid");

}

}

catch (SocSecException e) // To do: catch the SocSecException

{

System.out.println(e.getMessage());

}

System.out.print("Continue? ");

response = keyboard.nextLine();

answer = response.charAt(0);

}

}

private static boolean isValid(String number)throws SocSecException

{

boolean goodSoFar = true;

int index = 0;

// To do: Task #2 step 2

// 1. check the SSN length. Throw SocSecException if it is not 11

if (number.length() != 11)

{

throw new SocSecException("wrong number of characters ");

}

for( index=0;index<number.length();++index){

if(index==3 || index==6){

if (number.charAt(index) != '-'){

throw new SocSecException("dashes at wrong positions");

}

}else if (!Character.isDigit(number.charAt(index))){

throw new SocSecException("contains a character that is not a digit");

}

}

// 2. check the two "-" are in right position. Throw SocSecException if it is not

// if (number.charAt(3) != '-')

// 3. check other position that should be digits. Throw SocSecException if it is not

// if (!Character.isDigit(number.charAt(index)))

return goodSoFar;

}

}

See attachment

You might be interested in
What command would you use to map a share to a drive letter on a computer?
natulia [17]
What are the options
4 0
4 years ago
Using a graphic organizer in the prewriting can do all of the following except what?
ikadub [295]
A. organize the writers thoughts 
<span>B. help narrow the writers topic </span>
<span>C. research a writers story** </span>
<span>D. help make the writing more detailed.</span>
5 0
3 years ago
Both Wireshark and NetWitness Investigator can be used for packet captures and analysis. Which tool is preferred for each task,
NikAS [45]

Answer:

  • <u>packet capture best suited for Wireshark </u>
  • <u>packet analysis best suited for Netwiness</u>

Explanation:

Although both software packages can carry out each task, however, expert network administrators have noted that in terms of effectiveness, the Wireshark software application is best suited for packet capture since unlike Netwitness has no limitation on the size of files it can capture.

Whereas, because Netwitness has a capacity of up to seven-layer protocol analysis, it can perform a more detailed analysis of packets.

5 0
3 years ago
What is life all about?
zloy xaker [14]
Life can be about anything........
8 0
3 years ago
Read 2 more answers
2 why do we use the binary number system to store information on a computer
shusha [124]
Depending on the type of computer, we don't use binary. Analog and mechanical computers can express more than two values.

The electronic computers that we commonly use are electronic digital computers. Digital computers use binary. That way it's simple, if there's no voltage that's considered logical 0. If there is voltage it's considered logical 1.
4 0
4 years ago
Other questions:
  • With respect to the five components of social media information systems (SMIS), which of the following statements is true of SM
    11·1 answer
  • a limited-access expressway. A)allows vehicles to enter or exit only at certain place.B) does not permit trucks or buses.C)has n
    9·1 answer
  • When you use information hiding by selecting which properties and methods of a class to make public, you are assured that your d
    14·1 answer
  • Write a function called has_duplicates that takes a string parameter and returns True if the string has any repeated characters.
    15·1 answer
  • Please help with this
    8·1 answer
  • Every telecommunication setup uses two devices: one device to transmit data and one device to receive data. Which device transmi
    15·1 answer
  • What is the next line?
    7·1 answer
  • Any websites online to make $50 daily?​
    11·1 answer
  • Which of the following BEST describes the part of video or movie creation during which filming occurs, digital modelers create a
    9·2 answers
  • Alice is watching a speech over the internet. what type of message is alice attending to?
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!