Hello all,
I have an assignment to create a basic SpamBlocker using Java. I have the bulk of it created but came across an issue with the .LowerCase() function. Everything compiles correctly but the output is not what I expect (input: “make money fast” is different from “Make Money Fast” but I 'd like them to be the same). Here is my code: It relies on another piece of code called IO to compile correctly but I only need help with the .Lowercase() function. Thanks in advance.
public class SpamBlocker
{
public static void main(String[] args)
{
System.out.print("Enter the subject line of the e-mail: ");
String subject = IO.readString();
System.out.println("got user input, subject = " + subject);
subject.toLowerCase();
System.out.println("converted to lowercase, subject = " + subject);
boolean isSpam = false;
int makeIndex = subject.indexOf("make");
System.out.println("makeIndex = " + makeIndex);
int moneyIndex = subject.indexOf("money");
System.out.println("moneyIndex = " + moneyIndex);
int fastIndex = subject.indexOf("fast");
System.out.println("fastIndex = " + fastIndex);
if (makeIndex != -1 && moneyIndex != -1 && fastIndex != -1) {
System.out.println("setting isSpam to true, " +
"makeIndex = " + makeIndex +
"moneyIndex = " + moneyIndex +
"fastIndex = " + fastIndex);
isSpam = true;
}
System.out.println("after if statement, isSpam = " + isSpam + ", subject = " + subject);
if (isSpam) {
System.out.println("identified spam, isSpam = " + isSpam + ", subject = " + subject);
IO.outputStringAnswer("Message is spam.");
} else {
System.out.println("identified non-spam, isSpam = " + isSpam + ", subject = " + subject);
IO.outputStringAnswer("Message is legitimate.");
}
}
}