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?
Pig Latin translator
Page 1 of 15 Replies - 1913 Views - Last Post: 12 June 2009 - 11:12 AM
Replies To: Pig Latin translator
#2
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
#3
Re: Pig Latin translator
Posted 11 June 2009 - 05:35 PM
mostyfriedman, 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?
#4
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...
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" );
}
#5
Re: Pig Latin translator
Posted 11 June 2009 - 06:38 PM
delta134, 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?
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
#6
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.
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.
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote




|