5 Replies - 2879 Views - Last Post: 12 June 2009 - 11:12 AM Rate Topic: -----

#1 delta134  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 11-June 09

Pig Latin translator

Posted 11 June 2009 - 05:16 PM

Hey everyone. I've never programmed in Java before so please forgive me if my questions seem basic or I have trouble understanding. My assignment is to create a Pig Latin translator using the swing package (JOptionPane). I have spent some time going through various posts on Pig Latin translators. However, none of the codes involve the swing package. I understand that I can not ask for my code to be written for me, but my question is, since I have to use the swing package is that different than the String or Lang packages? Obviously it is different but what I mean is does the basic code change? Or is the code the same but the package used different?

Is This A Good Question/Topic? 0
  • +

Replies To: Pig Latin translator

#2 mostyfriedman  Icon User is offline

  • The Algorithmi
  • member icon

Reputation: 727
  • View blog
  • Posts: 4,473
  • Joined: 24-October 08

Re: Pig Latin translator

Posted 11 June 2009 - 05:30 PM

JOptionPane is just a mean to take input and give output using a simple graphical window..the code that does the rest of the job with this assignment will require no usage of swing packages
Was This Post Helpful? 1
  • +
  • -

#3 delta134  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 11-June 09

Re: Pig Latin translator

Posted 11 June 2009 - 05:35 PM

View Postmostyfriedman, on 11 Jun, 2009 - 04:30 PM, said:

JOptionPane is just a mean to take input and give output using a simple graphical window..the code that does the rest of the job with this assignment will require no usage of swing packages


Our professor told us we have to use the Java String class. So since he's saying we have to use Swing JOptionPane method does that just mean I put

import javax.swing.JOptionPane; before the class definition in my source file? And then I can use any basic Pig Latin translator code and just change the conditions specified?
Was This Post Helpful? 0
  • +
  • -

#4 jcmaster2  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 183
  • Joined: 27-April 09

Re: Pig Latin translator

Posted 11 June 2009 - 05:59 PM

Here is a simple one in C...

Note only handles -certain words- assignment you may have may dictate otherwise...

#include <stdio.h>
#include <string.h>

void printLatinWord(char *word); 

int main(void)
{ 
   char sentence[ 80 ]; 
   char *tokenPtr;	  // pointer to current token 
   
   printf( "Enter a sentence:\n" );
   gets( sentence );
   printf( "\nThe sentence in Pig Latin is:\n" );

   // call function strtok to alter the sentence 
   tokenPtr = strtok( sentence, " .,;" );
   
   // if tokenPtr does not equal NULL 
   while ( tokenPtr ) { 

	  // pass the token to printLatinWord and get next token 
	  printLatinWord( tokenPtr );
	  tokenPtr = strtok( NULL, " .,;" );
	  
	  // if tokenPtr not NULL, print space 
	  if ( tokenPtr ) {
		 printf( " " );
	  } 
   } 
   printf( "." );

   return 0; 
} 

/* print out the English word in pig Latin form */
void printLatinWord(char *word)
{ 
   unsigned int i; 

   // loop through the word 
   for ( i = 1; i < strlen( word ); i++ ) {
	  printf( "%c", word[ i ] );
   } 
   printf( "%c%s", word[ 0 ], "ay" );
}

Was This Post Helpful? 0
  • +
  • -

#5 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8328
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Pig Latin translator

Posted 11 June 2009 - 06:38 PM

View Postdelta134, on 11 Jun, 2009 - 04:35 PM, said:

Our professor told us we have to use the Java String class. So since he's saying we have to use Swing JOptionPane method does that just mean I put

import javax.swing.JOptionPane; before the class definition in my source file? And then I can use any basic Pig Latin translator code and just change the conditions specified?

You wont have the choice
You will need a String to get the values written in the JOptionPane by the user
And a String to write back your translation
Was This Post Helpful? 0
  • +
  • -

#6 bsheairs  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 03-June 09

Re: Pig Latin translator

Posted 12 June 2009 - 11:12 AM

Usually when I have an assignment dealing with a Java api that I have never used, I go to Sun's Java 6 API online. There are explanations of all the classes and examples.

The main api is here: http://java.sun.com/javase/6/docs/api/

Help for the String class you will need to use is here: http://java.sun.com/...ang/String.html

I don't really know how your teacher expects you to implement JOptionPane for your project. But here is a link to Sun's tutorial for the most frequent use of JOptionPane. Typically you use the JOptionPane for dialog boxes, or alerts.

http://java.sun.com/...nts/dialog.html

I hope those links help.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1