Click to See Complete Forum and Search --> : Soundex Assistance


rbd
10-03-2006, 01:13 AM
I have this assignment that I need to do but I cant for the life of me figure out how to set this up...My brain is dying on me I swear...
here is what I ahve...and Im sure there are some errors here.

import java.util.*;

public class Soundex
{
public static String getSoundex(String s);


public static char encode(char name);
{

switch(name)
{
case'B';
case'F';
case'P';
case'V';
return '1';
case'C';
case'G';
case'J';
case'K';
case'Q';
case'S';
case'X';
case'Z';
return '2';
case'D';
case'T';
return '3';
case'B';
case'L';
return '4';

case'B';
case'M';
case'N';
return '5';
case'R';
return '6';
default
return '0';
}
}

public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.println("Enter a Name: ")
s = nextInt();
if(s= "")
return getSoundex();

}

}


I dont know how to initiate the soundex code or what kind of loop I need for the main method.
Any help would be great.
Thank you,
rb

agent_x91
10-03-2006, 08:30 AM
The semicolons on the end of each case statement should be colons; that switch statement doesn't make much sense.

Try this:


switch(name)
{
case 'B':
case 'F':
case 'P':
case 'V':
return '1';
case 'C':
case 'G':
case 'J':
case 'K':
case 'Q':
case 'S':
case 'X':
case 'Z':
return '2';
case 'D':
case 'T':
return '3':
case 'B':
case 'L':
return '4';

case 'B':
case 'M':
case 'N':
return '5';
case 'R':
return '6';
default:
return '0';
}
return '0';
}

agent_x91
10-03-2006, 08:32 AM
Also, why have you ended this method declaration here:


public static String getSoundex(String s);


What is the getSoundex() method meant to do?

rbd
10-03-2006, 09:34 AM
Im supposed to define a method for soundex...even though it doesnt seem right.. : /