Hi, everyone. For my programming homework, we have to write a code based on the Soundex algorithm that is used by New York State Immunization Information System. Here are the instructions/rules:http://www.cis.temple.edu/~ingargio/cis67/homeworks/homework6f08.html. My problem is that (besides having no idea what to do) I have an infinite loop somewhere in the code. The result is that it doesn't even transcode the input. It simply quits or it hangs after user input. Can anyone help?

import java.util.Scanner;

public class Nysiis
{

public static boolean isVowel(String a){
if (a.equals("A")){
return true;
}
if (a.equals("E")){
return true;
}

if (a.equals("I")){
return true;
}
if (a.equals("O")){
return true;
}
if (a.equals("U")){
return true;
}
else
return false;
}

public static String getNysiis(String s){
int pointer = 0;
s = s.toUpperCase();
String v="";
String t= "";
int length = s.length();

if(s.startsWith("MAC")){
t += "MCC";
pointer = pointer + 3;
}

if(s.startsWith("KN")){
t += "NN";
pointer = pointer + 2;
}

if(s.startsWith("K")){
t += "C";
pointer = pointer + 1;
}

if(s.startsWith("PH")){
t += "FF";
pointer = pointer + 2;
}

if(s.startsWith("PF")){
t += "FF";
pointer = pointer + 2;
}

if(s.startsWith("SCH")){
t += "SSS";
pointer = pointer + 3;
}

Scanner characters = new Scanner(s + pointer);


while(characters.hasNext()){
        t += s.substring(pointer);
        if (s.startsWith("SCH")){
                v = t + "SSS";
                s = s.substring(3);
        } else if (s.startsWith("PH")) {
                v = t + "FF";
                t = s.substring(2);
        }
          else if (s.startsWith("KN")){
                v = t + "NN";
                t = s.substring(2);
        }
          else if (s.startsWith("K")){
                v = t + "C";
                t = s.substring(1);
        }

          else if (s.startsWith("EV")){
                v = t + "AF";
                t = s.substring(2);
        }
           else if (s.startsWith("Q")){
                v = t + "G";
                t = s.substring(1);
        }

           else if (s.startsWith("Z")){
                v = t + "S";

 }

           else if (s.startsWith("M")){
                v = t + "N";
                t = s.substring(1);


        }
}




return v;
}

public static void main(String[] args){
Scanner transcode= new Scanner(System.in);
System.out.println("Enter a name please ");
String s= transcode.next();
while (transcode.hasNext()){
String v = getNysiis(s);
System.out.println(v);
}
}
}

Scanner implements the Iterator interface. So you have to use next() to go to the next element somewhere inside your while loops.

In other words the scanner is checking to see if there are more elements left. But you never move to the next element in your code.

But where would I put that piece of code? I'm confused basically on how the loops should interact with each other. I have a loop that recoded the first letter of the letter but how would I implement the other loops to finish recoding the name?

This article has been dead for over six months. Start a new discussion instead.