If this is the given input:
An Uncensored Input:
Name: John Doe
Email: john@school.edu
Phone: 456-832-7180
This is what I want:
The newly Censored input:
Name: J*** **e
Email: j***@s*****.edu
Phone: XXX-XXX-7180
These are the instructions given to me: When censoring information, we will be using the following format:
“Type: Information_here\n”
○ Type we want to filter can be “Name”, “Email” or “Phone”
○ There will always be a colon and a space between the “Type” and “Information_here”
○ Each line will end with a newline character (\n)
I tried using array list and substrings in order to isolate first and last name but somehow could not do it. The problem is that the user could enter either just name or just phone or all three or any two. That has made this very annoying. My if statements don't work even though I am able to censor it.
this is where i have gotten:
System.out.println("Please enter the phrase you would like to censor information from: ");
while (true) {
// Obtain a line from the user
String temp = scanner.nextLine();
if (!passage.isEmpty() && temp.isEmpty()) {
break;
} else if (passage.isEmpty() && temp.isEmpty()) {
continue;
}
// Add the contents of temp into the phrase
passage += temp;
// Append a newline character to each line for parsing
// This will separate each line the user enters
// To understand how input is formatted in Part 3, please refer to the handout.
passage += '\n';
}
// Print the uncensored passage
System.out.println("Uncensored: ");
System.out.println(passage);
ArrayList<String> obj = new ArrayList<String>();
String s[] = passage.split("/n");
obj.addAll(Arrays.asList(s));
String what = obj.get(0);
String cens = "";
if (what.substring(0, 1) == "N"){
String whole = what.substring(6,what.length());
int space = whole.indexOf(" ");
String first = whole.substring(0,space);
String last = whole.substring(space, whole.length());
String fcen = first.substring(0,1);
for (int i = 1; i < first.length(); i++){
fcen += "*";
cens += fcen;
}