Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Java language all in the same file What is this lab about and what will you be w

ID: 3814960 • Letter: J

Question


Java language all in the same file What is this lab about and what will you be working on? In this lab, you will practice new tools and concepts you've learned in class and in lab since midterm Namely, this lab will be on methods, arrays (1D and 2D) and on repetition (via loops and recursion). this you will have to completetwo activities. Here is what you have todo. Activity [60 points] Method Luhn, You will have to implement the Luhn Checksum validation algorithm to check whether a credit card or This is a widely used algorithm that checks that you enter a valid credit card number when you are trying to make a purchase. Short description of the algorithm tThink like a Programmer an Introduction to Creative Problem solving by V. A Spraul): Using the original number, double the value of every other digit, starting with the leftmost one, as shown below. Then add the values ofthe individual digits toRether (if a doubled value now has two digits, add the digits together see below) The identification number is valid if the sum is divisible by 10 (ae, the sum has to be a of 10 Example of execution of the algorithm: Suppose you want to check that your credit card number is valid. You credit card number is 8273 1232 7351 0569. Let's see how to checkit: First, you are going to double every other number, starting with the first number (here it is number 80: And you obtain: 14 But we do not want double digits, soforevery number that now has double digits, weadd these digits: And we obtain: Now we add all of these numbers: 7 2 5 3+ 2 2+ 6 2 5 3 1 1 0 S +3+ 9 56 56 is not a multiple of 10, so the credit card number was a fake...

Explanation / Answer

Here is the code for you:

import java.io.*;
import java.util.*;
class CheckCustomerIterative
{
    public static boolean Luhn(String cardNumber)
    {
       int sum = 0;
       for(int i = 0; i < 15; i++)
       {
          if(i % 2 == 0)
          {
             int temp = 2 * (cardNumber.charAt(i) - '0');
             sum += temp;
          }  
          else
              sum += (cardNumber.charAt(i) - '0');
       }
       return sum % 10 == 0;
    }
    public static void checkCustomers(String[][] customers, int count) throws FileNotFoundException
    {
       PrintWriter pw = new PrintWriter(new File("Customers.error"));
       for(int i = 0; i < count; i++)
       {
          if(!Luhn(customers[i][1]))
              pw.write(customers[i][0] + " " + customers[i][1] + " ");
       }
       pw.close();
    }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote