In: Computer Science
In this assignment you are developing a fraud detection system to detect fraudulent activities based on this Decision Three. Your program receives a comma separated transaction log with the below format as its input:
[amount],[# of transactions in last day],[area code],[transaction time]
Your program should use string operations to decompose the transaction log and store its elements in variables of appropriate types. Then, based on the values of those attributes and the decision three, it attaches either a ",fraud" or ",no fraud" at the end of the transaction log and prints it to the console. (Note: Assume that the area code can only be 31451,42683,90902,10267
For example, if the input is:
1000,4,90902,0602
The output will be:
1000,4,90902,0602,no fraud
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
/* Type your code here. */
int amount;
int noOfTransactions;
int areaCode;
String transactionTime;
}
}
Hi, please find the code for it below, and let me know in case of any doubts:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
System.out.println("Please enter the transaction log: ");
String log = scnr.next();
String arr[] = log.split(",");
int amount;
int noOfTransactions;
int areaCode=0;
String transactionTime;
if(arr.length>0)
amount = Integer.parseInt(arr[0]);
if(arr.length>1)
noOfTransactions=Integer.parseInt(arr[1]);
if(arr.length>2)
areaCode = Integer.parseInt(arr[2]);
if(arr.length>3)
transactionTime = arr[3];
if(areaCode==31451 ||areaCode==42683 || areaCode==90902 ||areaCode==10267) {
log=log+",no fraud";
}
else {
log=log+",fraud";
}
System.out.println(log);
}
}
sample outputs :