alegramer
02-14-2012, 02:46 AM
need help with an encryption program
i haven't been able to get these to work
-Print an error message and exit if the sentence
* Contains a non-alphabetic character other than space
or the following punctuation marks:
! , . ? - : ; ( ) [ ] / " '
* Does not end with '.', '!' or '?'.
so how do i scan the input string for those special characters?
how do i Display an input dialog asking player 2 for a guess
in the form: a=b. using the javax.swing.JOptionPane;
this is what i got so far
import javax.swing.JOptionPane;
public class CodeCrackerGame
{
public static void main(String[] args)
{
//----------------------------------asks p1 to input 1st sentence---------------------------------
String oSentence = JOptionPane
.showInputDialog("player 1 enter asentence with up to 100 characters and at least 7 words");
String[] test1 = oSentence.split(" ");// separates the whole sentence out by
// words to find many words there are
if (test1.length < 7 || oSentence.length() > 100)
{
JOptionPane.showMessageDialog(null, //checks length of sentence/characters
"ERROR= input is less than 7 words"
+ " or has more than a 100 characters!");
System.exit(0);
}
for (int i = 0; i < oSentence.length(); i++)
{
if (Character.isDigit(oSentence.charAt(i))) ;
{
System.out.println(" there is digit in the input @ " + i);
}
}
// int start = 0;
// char c = oSentence.charAt(start);
// while (!Character.isDigit(c))
// { start++;
// / c = oSentence.charAt(start);
// }
// JOptionPane.showMessageDialog(null, // converts all to upper case
// "ERROR= number on input" );
// System.exit ( 0 );
String newSentence = oSentence.toUpperCase();
JOptionPane.showMessageDialog(null, //Converts 1st sentence to uppercase
" Input Sentence= " + newSentence);
//----------------------------------asks p2 to innpur 2nd sntence---------------------------------
String o2Sentence = JOptionPane
.showInputDialog("player 1 enter a keyword with up to 10 characters");
if (o2Sentence.length() < 3 || o2Sentence.length() > 10)
{
JOptionPane.showInputDialog("ERROR= input is less than 3 characters " //checks length of sentence/characters
+ " or has more than a 10 characters!");
}
}
}
thanks for any help in advance
i haven't been able to get these to work
-Print an error message and exit if the sentence
* Contains a non-alphabetic character other than space
or the following punctuation marks:
! , . ? - : ; ( ) [ ] / " '
* Does not end with '.', '!' or '?'.
so how do i scan the input string for those special characters?
how do i Display an input dialog asking player 2 for a guess
in the form: a=b. using the javax.swing.JOptionPane;
this is what i got so far
import javax.swing.JOptionPane;
public class CodeCrackerGame
{
public static void main(String[] args)
{
//----------------------------------asks p1 to input 1st sentence---------------------------------
String oSentence = JOptionPane
.showInputDialog("player 1 enter asentence with up to 100 characters and at least 7 words");
String[] test1 = oSentence.split(" ");// separates the whole sentence out by
// words to find many words there are
if (test1.length < 7 || oSentence.length() > 100)
{
JOptionPane.showMessageDialog(null, //checks length of sentence/characters
"ERROR= input is less than 7 words"
+ " or has more than a 100 characters!");
System.exit(0);
}
for (int i = 0; i < oSentence.length(); i++)
{
if (Character.isDigit(oSentence.charAt(i))) ;
{
System.out.println(" there is digit in the input @ " + i);
}
}
// int start = 0;
// char c = oSentence.charAt(start);
// while (!Character.isDigit(c))
// { start++;
// / c = oSentence.charAt(start);
// }
// JOptionPane.showMessageDialog(null, // converts all to upper case
// "ERROR= number on input" );
// System.exit ( 0 );
String newSentence = oSentence.toUpperCase();
JOptionPane.showMessageDialog(null, //Converts 1st sentence to uppercase
" Input Sentence= " + newSentence);
//----------------------------------asks p2 to innpur 2nd sntence---------------------------------
String o2Sentence = JOptionPane
.showInputDialog("player 1 enter a keyword with up to 10 characters");
if (o2Sentence.length() < 3 || o2Sentence.length() > 10)
{
JOptionPane.showInputDialog("ERROR= input is less than 3 characters " //checks length of sentence/characters
+ " or has more than a 10 characters!");
}
}
}
thanks for any help in advance