Question

Let’s say a user inputs Washington Lim who is on the sanctions list. The program needs...

Let’s say a user inputs Washington Lim who is on the sanctions list. The program needs to match the input name (Washington Lim) with the banned list to see if a match is found, e.g.Washington Lim could also be spelt as Washington Tim. Or while there could be typo while typing the input (user could have interchanged 2 letters e.g. Washingtno Lim). These should also show up as matches / hits. Let’s define 75% match as a hit. “Washington Lim” has 14 characters including the space. If we take only integers then even if 3 characters are incorrect, it should be deemed as a hit. So “Washington Tim" which has only one character incorrect when compared to “Washington Lim” should be returned as a hit.

Assume the Banned list has the following names

• Washington Lim

• Russia

• PETA

Input a name on the command prompt, match it with the above list and return a “Hit” or “No hit” based on a 75% match.

Expected technical output

A Reusable Java program w/ Classes which can used to Identify Payee is Matching against given banned list (List which contains Names of people, Organizations and Countries provided as part of CSV file) and returns with Hit / No with Percentages

Expected user action/input

input name through command line argument OR build a simple rest endpoint in Java

What technical stack

Java Implementation WITH OR WITHOUT Rest endpoint

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

sol: For the above question we have to check if the entered name belongs to banned list or not. We have to use Java language. The input file will be a csv file that is excel sheet. The output screen can be a rest endpoint or commandline. We shall use command line arguement for simplicity. We have to create a class, have reusable code(function) and output the hit/no hit with percentages.

NOTE: Make sure to save the file name as <classname>.java. Our program classname is Hit so save the file as Hit.java else the program will fail to run. If you want to keep a different file name make sure to change the classname too. If any other errors are encountered in execution please check the JDK version on your device. I am using JDK 8. The excel sheet created is saved as .csv ( comma delimited) format in my system.

CODE:

import java.io.*;
import java.util.Scanner;
public class Hit
{
static int dist(String s1, String s2) //finding distance between strings
{
int i = 0, c = 0, k;
  
if(s1.length()<s2.length())//checking length difference
k=s1.length();//storing smaller length
else
k=s2.length();
while (i < k)
{
if (s1.charAt(i) != s2.charAt(i)) //checking character similarity
c++; //incrementing counter for differences
i++;
}
c=c+(Math.abs(s1.length()-s2.length()));//adding length difference to the counter value and using abs to get magnitude only of negative difference
return c;
}
public static void main(String[] args) throws Exception
{
String str;
int k;
double p;
Scanner sc = new Scanner(new File("C:\\Users\\Santanu Karmakar\\Documents\\banlist.csv"));//taking file input
Scanner t=new Scanner(System.in);//creating another scanner object for user input
System.out.println("Enter your name: ");
String s= t.nextLine();
while (sc.hasNextLine()) //as long as file has lines we shall read
{
str=sc.nextLine(); //reading 1 file line
k=dist(s,str);//calling distance function, since it is static we call it without creating object

p=(s.length()-k)/(double)s.length()*100;//k holds difference in characters thats why to get percentage we find (length -k) /length because length-k gives the number of similar characters
if(p>=75.0)//cheching if similarity more than or equals 75%
System.out.println(str+": HIT, percentage match: "+p);//printing hit
else
System.out.println(str+": NO HIT, percentage match: "+p);

}   
sc.close();   
}
}

CODE SNAPSHOT:

INPUT FILE:

EXECUTION:

2 test cases shown.

Add a comment
Know the answer?
Add Answer to:
Let’s say a user inputs Washington Lim who is on the sanctions list. The program needs...
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
  • You are to write a program name Bank.java that maintains a list of records containing names...

    You are to write a program name Bank.java that maintains a list of records containing names and balance of customers. The program will prompt the user for a command, execute the command, then prompt the user for another command. The commands must be chosen from the following possibilities:           a    Show all records           r     Remove the current record           f     Change the first name in the current record           l     Change the last name in the current record           n    Add a new record           d   ...

  • The following are screen grabs of the provided files Thanks so much for your help, and have a n...

    The following are screen grabs of the provided files Thanks so much for your help, and have a nice day! My Java Programming Teacher Gave me this for practice before the exam, butI can't get it to work, and I need a working version to discuss with my teacher ASAP, and I would like to sleep at some point before the exam. Please Help TEST QUESTION 5: Tamagotchi For this question, you will write a number of classes that you...

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