Hi i need help with a asighnment, i am supposed to take an existing pig latin transualater and modify it to deal correctly with capitals and punctuation, i am currently at a loss at what to do.
here is the class file:

import java.util.Scanner;

public class PigLatinTranslator
{
   public static String translate (String sentence)
   {
      String result = "";

      sentence = sentence.toLowerCase();

      Scanner scan = new Scanner (sentence);
      while (scan.hasNext())
      {
         result += translateWord (scan.next());
         result += " ";
      }

      return result;
   }
   private static String translateWord (String word)
   {
      String result = "";

      if (beginsWithVowel(word))
         result = word + "yay";
      else
         if (beginsWithBlend(word))
            result = word.substring(2) + word.substring(0,2) + "ay";
         else
            result = word.substring(1) + word.charAt(0) + "ay";

      return result;
   }
   private static boolean beginsWithVowel (String word)
   {
      String vowels = "aeiou";

      char letter = word.charAt(0);

      return (vowels.indexOf(letter) != -1);
   }
   private static boolean beginsWithBlend (String word)
   {
      return ( word.startsWith ("bl") || word.startsWith ("sc") ||
               word.startsWith ("br") || word.startsWith ("sh") ||
               word.startsWith ("ch") || word.startsWith ("sk") ||
               word.startsWith ("cl") || word.startsWith ("sl") ||
               word.startsWith ("cr") || word.startsWith ("sn") ||
               word.startsWith ("dr") || word.startsWith ("sm") ||
               word.startsWith ("dw") || word.startsWith ("sp") ||
               word.startsWith ("fl") || word.startsWith ("sq") ||
               word.startsWith ("fr") || word.startsWith ("st") ||
               word.startsWith ("gl") || word.startsWith ("sw") ||
               word.startsWith ("gr") || word.startsWith ("th") ||
               word.startsWith ("kl") || word.startsWith ("tr") ||
               word.startsWith ("ph") || word.startsWith ("tw") ||
               word.startsWith ("pl") || word.startsWith ("wh") ||
               word.startsWith ("pr") || word.startsWith ("wr") ); 
   }
}

Which part is confusing you? What have you tried? What have you thought about trying?

From the forum rules:
Do provide evidence of having done some work yourself if posting questions from school or work assignments

Simply dumping your assignment here is not evidence of effort.

I guess i am not sure how to go about it. i have started to try some different aproaches but have always ended up not knowing how to do something, here is something i started to deal with captilization, its not finished though.

import java.util.Scanner;

public class PigLatinTranslator
{
   public static String translate (String sentence)
   {
      String result = "";

      Scanner scan = new Scanner (sentence);
      while (scan.hasNext())
      {
         result += translateWord (scan.next());
         result += " ";
      }

      return result;
   }
   private static String translateWord (String word)
   {
      String result = "";

      if (beginsWithVowel(word))
         result = word + "yay";
      else
	if (beginsWithCaps(word))
         if (beginsWithBlend(word))
            result = word.substring(2) + word.substring(0,2) + "Ay";
              
         else
            result = word.substring(1) + word.charAt(0) + "ay";
	 else
          if (beginsWithBlend(word))
            result = word.substring(2) + word.substring(0,2) + "ay";
              
          else
            result = word.substring(1) + word.charAt(0) + "ay";
      return result;
   }
   private static boolean beginsWithVowel (String word)
   {
      String vowels = "aeiou";

      char letter = word.charAt(0);

      return (vowels.indexOf(letter) != -1);
   }
   private static boolean beginsWithBlend (String word)
   {
      return ( word.startsWith ("bl") || word.startsWith ("sc") ||
               word.startsWith ("br") || word.startsWith ("sh") ||
               word.startsWith ("ch") || word.startsWith ("sk") ||
               word.startsWith ("cl") || word.startsWith ("sl") ||
               word.startsWith ("cr") || word.startsWith ("sn") ||
               word.startsWith ("dr") || word.startsWith ("sm") ||
               word.startsWith ("dw") || word.startsWith ("sp") ||
               word.startsWith ("fl") || word.startsWith ("sq") ||
               word.startsWith ("fr") || word.startsWith ("st") ||
               word.startsWith ("gl") || word.startsWith ("sw") ||
               word.startsWith ("gr") || word.startsWith ("th") ||
               word.startsWith ("kl") || word.startsWith ("tr") ||
               word.startsWith ("ph") || word.startsWith ("tw") ||
               word.startsWith ("pl") || word.startsWith ("wh") ||
               word.startsWith ("pr") || word.startsWith ("wr") ); 
   }
   private static boolean beginsWithCaps (String word)
   {
	return (word.startsWith ("A") || word.startsWith ("B") ||
	word.startsWith ("C") || word.startsWith ("D") ||
	word.startsWith ("E") || word.startsWith ("F") ||
	word.startsWith ("G") || word.startsWith ("H") ||
	word.startsWith ("I") || word.startsWith ("J") ||
	word.startsWith ("K") || word.startsWith ("L") ||
	word.startsWith ("M") || word.startsWith ("N") ||
	word.startsWith ("O") || word.startsWith ("P") ||
	word.startsWith ("Q") || word.startsWith ("R") ||
	word.startsWith ("S") || word.startsWith ("T") ||
	word.startsWith ("U") || word.startsWith ("V") ||
	word.startsWith ("X") || word.startsWith ("Y") ||
	word.startsWith ("Z") );
} 
}

i am sorry i dont know much about java, and all my teacher does is read the powerpoints that came with the book. so i am not learning much from him:(

okay so i got punctuation taken care of, but i am having troule getting caps to work, here is my program so far

import java.util.Scanner;

public class PigLatinTranslator
{
   public static String translate (String sentence)
   {
      String result = "";

      Scanner scan = new Scanner (sentence);
      while (scan.hasNext())
      {
         result += pun (scan.next());
         result += " ";

      }
	
	

      return result;
   }
   private static String pun(String s) {
    String result = "";
    int i = 0;
    while (i<s.length()) {

      while (i<s.length() && !isLetter(s.charAt(i))) {
        result = result + s.charAt(i);
        i++;
      }

      if (i>=s.length()) break;

      int begin = i;
      while (i<s.length() && isLetter(s.charAt(i))) {
        i++;
      }
      int end = i;
      result = result + translateWord(s.substring(begin, end));
    }
    return result;
  }

  private static boolean isLetter(char c) {
    return ( (c >='A' && c <='Z') || (c >='a' && c <='z') );
  }


   private static String translateWord (String word)
   {
      String result = "";

      if (beginsWithVowel(word))
         result = word + "yay";
      else 
         if (beginsWithBlend(word))
            result = word.substring(2) + word.substring(0,2) + "ay";
         else
            result = word.substring(1) + word.charAt(0) + "ay";

      return result;
	if (hasCaps(word))
	result = word.toLowerCase() + Character.toUpperCase(word.charAt(0));
	
	return result;
   }
   private static boolean beginsWithVowel (String word)
   {
      String vowels = "aeiou";

      char letter = word.charAt(0);

      return (vowels.indexOf(letter) != -1);
   }
   private static boolean beginsWithBlend (String word)
   {
      return ( word.startsWith ("bl") || word.startsWith ("sc") ||
               word.startsWith ("br") || word.startsWith ("sh") ||
               word.startsWith ("ch") || word.startsWith ("sk") ||
               word.startsWith ("cl") || word.startsWith ("sl") ||
               word.startsWith ("cr") || word.startsWith ("sn") ||
               word.startsWith ("dr") || word.startsWith ("sm") ||
               word.startsWith ("dw") || word.startsWith ("sp") ||
               word.startsWith ("fl") || word.startsWith ("sq") ||
               word.startsWith ("fr") || word.startsWith ("st") ||
               word.startsWith ("gl") || word.startsWith ("sw") ||
               word.startsWith ("gr") || word.startsWith ("th") ||
               word.startsWith ("kl") || word.startsWith ("tr") ||
               word.startsWith ("ph") || word.startsWith ("tw") ||
               word.startsWith ("pl") || word.startsWith ("wh") ||
               word.startsWith ("pr") || word.startsWith ("wr") ); 
   }
   private static boolean hasCaps (String word)
   {
    for (int ch = 0; ch < word.length(); ch++)
   {
	char current;
	current = word.charAt(ch);
         return (current >= 'A' && chcurrent <= "Z");
   }
   }
	
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.