Question

Instructions In this problem, you will update the declaration for a function called validateSIN (), using the@paran and @re t

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Java Code

public class Test {

  
   /*
   * @Param : sIN is a String that is to be validated
   *
   * @return : boolean value that represents the validation status of the given String
   */
   public static boolean validateSIN(String sIN) {

       if (sIN.length() == 11) {
          
           int total=0;

           sIN = sIN.replaceAll("-", "");
      
           int[] ints = new int[9];
           for(int i=0;i<sIN.length();i++) {
              
               ints[i] = Integer.parseInt(sIN.charAt(i)+"");
              
               if(i%2!=0) {
                   ints[i] = ints[i]*2;
               }
              
               if(ints[i]<10) {
                   total = total + ints[i];
               }
              
               else {
                   int rem = ints[i]%10;
                   total = total + 1 + rem;
               }
           }
          
           if(total%10==0)
               return true;
          
          
       }
       return false;

   }

   public static void main(String[] args) {

       String st1 = "123-456-782";
       String st2 = "145-454-457";
       System.out.println("Is "+st1+" valid? : "+validateSIN(st1));
       System.out.println("Is "+st2+" valid? : "+validateSIN(st2));
      
   }
}

OutPut

Is 123-456-782 valid? : true
Is 145-454-457 valid? : false

Feel free to ask any doubts, if you face any difficulty in understanding.

Please upvote the answer if you find it helpful

Add a comment
Know the answer?
Add Answer to:
Instructions In this problem, you will update the declaration for a function called validateSIN (), using...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Instructions Good news! You have are nearly finished with the semester! Today’s problem is going to...

    Instructions Good news! You have are nearly finished with the semester! Today’s problem is going to be to modify a program to match the actual check used to verify Social Insurance Numbers. Don’t worry, the first part of the solution has been taken care of for you. You just need to modify it to also check the bits in BOLD font. A valid SIN is calculated by multiply odd-positioned digits (1st, 3rd, 5th, 7th, & 9th) by 1 and even-positioned...

  • Using the above described algorithm, create a program that: (IN PYTHON) 1.Asks the user which type...

    Using the above described algorithm, create a program that: (IN PYTHON) 1.Asks the user which type of credit card he/she would like to find the checksum for. 2. Based on the user's choice of credit card, asks the user for the n digits of the credit card. [Get the input as a string; it's easier to work with the string, so don't convert to an integer.] 3. Using the user's input of the n digits, finds the last digit of...

  • Using loops with the String and Character classes. You can also use the StringBuilder class to...

    Using loops with the String and Character classes. You can also use the StringBuilder class to concatenate all the error messages. Floating point literals can be expressed as digits with one decimal point or using scientific notation. 1 The only valid characters are digits (0 through 9) At most one decimal point. At most one occurrence of the letter 'E' At most two positive or negative signs. examples of valid expressions: 3.14159 -2.54 2.453E3 I 66.3E-5 Write a class definition...

  • this is a C++ program! You will write a program that performs the following tasks for...

    this is a C++ program! You will write a program that performs the following tasks for a simple mathematical calculator: (1) Open a user-specified file for input. Prompt for the name of the file, read it into a string variable, echo print it to the terminal and then open it. If the file is not opened, enter into a loop that prints out an error message, resets the input file stream variable (see the hints section), obtains a new file...

  • I need help with this assignment in C++, please! *** The instructions and programming style detai...

    I need help with this assignment in C++, please! *** The instructions and programming style details are crucial for this assignment! Goal: Your assignment is to write a C+ program to read in a list of phone call records from a file, and output them in a more user-friendly format to the standard output (cout). In so doing, you will practice using the ifstream class, I'O manipulators, and the string class. File format: Here is an example of a file...

  • matlab 28 pts Question 8 Problem 4. Write the following function. Do NOT hard code using...

    matlab 28 pts Question 8 Problem 4. Write the following function. Do NOT hard code using any of the examples. Your function should work for all possible inputs as specified by the problem. Hard coding will result in significant point loss. (B) (28 Points) Function Name: birthday Party Input (2): (char) An Mx 11 array formatted with information about various birthdays (char) An MxN array of names Output (l): (char) A string containing information about the best birthday Function Description:...

  • Objective In this assignment, you will practice solving a problem using object-oriented programming and specifically, you...

    Objective In this assignment, you will practice solving a problem using object-oriented programming and specifically, you will use the concept of object aggregation (i.e., has-a relationship between objects). You will implement a Java application, called MovieApplication that could be used in the movie industry. You are asked to implement three classes: Movie, Distributor, and MovieDriver. Each of these classes is described below. Problem Description The Movie class represents a movie and has the following attributes: name (of type String), directorName...

  • Using MATLAB. As an engineer working on designing and modelling a new drone product, you are...

    Using MATLAB. As an engineer working on designing and modelling a new drone product, you are doing a lot of different physics calculations. Your boss wants to write a program that can choose from an assortment of calculations and perform the desired physics calculation in order to streamline the design and modelling process. For this project you will write a function called PhysicsCalc. inputs Your function should take three inputs in the following order: var1–The first number in the calculation...

  • In this practice program you are going to practice creating graphical user interface controls and placing...

    In this practice program you are going to practice creating graphical user interface controls and placing them on a form. You are given a working NetBeans project shell to start that works with a given Invoice object that keeps track of a product name, quantity of the product to be ordered and the cost of each item. You will then create the necessary controls to extract the user input and display the results of the invoice. If you have any...

  • CSC110 Lab 6 (ALL CODING IN JAVA) Problem: A text file contains a paragraph. You are to read the contents of the file, store the UNIQUEwords and count the occurrences of each unique word. When the fil...

    CSC110 Lab 6 (ALL CODING IN JAVA) Problem: A text file contains a paragraph. You are to read the contents of the file, store the UNIQUEwords and count the occurrences of each unique word. When the file is completely read, write the words and the number of occurrences to a text file. The output should be the words in ALPHABETICAL order along with the number of times they occur and the number of syllables. Then write the following statistics to...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT