Re: Trouble with the driver and classes that work with the driver.
Teresa wrote:
this first part is the driver. need help with getting them both to work
with each other.
[ Snip class 1 ]
>
public class EnterState {
public String getAbbre(String userInput)
Change this line to:
public static String getAbbre(String userInput)
and it will work. See http://java.sun.com/docs/books/tutorial/index.html
for more information.
public int getResults(int abbre1, int abbre2) {
String theResult;
switch (abbre1) {
> case 'A': case 'a':
> switch (abbre2) {
case 'L': case 'l':
> System.out.print("Alabama");
> break;
[ snip everything else ]
[ NOTE: code reformatted to save screen space ]
Several nits:
1. Your second method does not seem to do quite what you want it to.
Characters should be passed as chars, not ints. Strings should be
returned as a String, not an int.
2. Try to be more descriptive than "they don't work."
3. Massive switch statements are not very ideal. Although the best was
would be to use a HashMap, since I assume that you are writing this as
part of an introductory class, that would probably be a bit beyond you
right now. At the very least, it is clearer to use code along the lines of:
// String abbreviation is passed in
abbreviation = abbreviation.toUpperCase();
if (abbreviation.equals("AL"))
return "Alabama";
else if (abbreviation.equals("AK"))
return "Alaska";
// etc.
--
Beware of bugs in the above code; I have only proved it correct, not
tried it. -- Donald E. Knuth