Hello all,
I am in an intro to Java class right now and I have an assignment due later today that converts a body of text to piglatin.
We are given a driver class which cannot be changed.
import java.util.*; public class PigDriver{ public static void main(String[] args){ Scanner scan = new Scanner(System.in); String t = " "; Piglatin p =new Piglatin(); while(t.length() > 0){ t = scan.nextLine(); t = t.toLowerCase(); p.pigConvert(t); } p.pigReport(); } }
and I have the following code written:
import java.util.StringTokenizer; import java.lang.String; public class Piglatin{ StringBuffer cookies; public Piglatin(){ } public StringBuffer pigConvert(String m) { StringBuffer result = new StringBuffer(); String delimiters = " ,.:;()[]{}\"'!@#$%^&*"; StringTokenizer lexer; String token; lexer = new StringTokenizer(m, delimiters, true); while (lexer.hasMoreTokens()) { token = lexer.nextToken(); if (delimiters.indexOf(token) > -1) result.append(token); else result.append(transformToken(token)); } cookies = result; return cookies; } public static String transformToken(String original) { StringBuffer result = new StringBuffer(); String vowels = "aeiou"; String vowelRule = "way"; String consonantRule = "ay"; if (vowels.indexOf(original.substring(0, 1).toLowerCase()) > -1) { result.append(original); result.append(vowelRule); } else { result.append(original.substring(1)); result.append(original.substring(0, 1)); result.append(consonantRule); } return result.toString(); } public void pigReport(){ System.out.println("something"); } }
The problem is that I can't print the converted text to the console. Normally I would just try to write a print statement into the method that's converting it, but I must follow the driver class. I wanted to make a stringbuffer (in this case cookies) that would exist outside of the pigConvert method, but when I try to print this it prints nothing. Any help would be greatly appreciated.
Thanks so much!


LinkBack URL
About LinkBacks
Reply With Quote
by clicking the
button on their useful posts.