Someone Please help me, I've no idea y it doesn't work?? :confused:
import javax.swing.JOptionPane; //Program uses JOptionPane
public class Homework5 {
//Main method to begin Java application
public static void main (String args[]) {
int NumberWord1 = 0;
int NumberWord2 = 0;
//User Enter's the 1st word
String Word1 = JOptionPane.showInputDialog(null,"Enter First Word",
"Homework5",JOptionPane.QUESTION_MESSAGE);
//Calculate the length of 1st word
NumberWord1 = Word1.length();
//Check Character in Word1
while (NumberWord1 >= 37) {
JOptionPane.showMessageDialog(null,"LengthWord1 = "+""+Word1.length()
+"\n Character in your First Word exceeds 37 character \n Please Re-Enter your First Word",
"Homework5",JOptionPane.ERROR_MESSAGE);
//User Re-Enter's First Word
Word1 = JOptionPane.showInputDialog(null,"Enter First Word",
"Homework5",JOptionPane.QUESTION_MESSAGE);
//Calculate the length of 1st word
NumberWord1 = Word1.length();
}
//User Enter's Second Word
String Word2 = JOptionPane.showInputDialog(null,"Enter Second Word",
"Homework5",JOptionPane.QUESTION_MESSAGE);
//Calculate the length of 2nd word
NumberWord2 = Word2.length();
//Check Character in Word2
while (NumberWord2 >= 37) {
JOptionPane.showMessageDialog(null,"LengthWord2 = "+""+Word2.length()+"\n Character in your Second Word exceeds 37 character \n Please Re-Enter your Second Word",
"Homework5",JOptionPane.ERROR_MESSAGE);
//User Re-Enter's Second Word
Word2 = JOptionPane.showInputDialog(null,"Enter Second Word",
"Homework5",JOptionPane.QUESTION_MESSAGE);
}
//Assigning Dots
char Dots ='.';
int TotalDots = 40;
int Dots1;
int Dots2;
//Calculate Dots
Dots1 = TotalDots - 1 - Word1.length() - Word2.length();
//Dots Results
String Results = "";
do {
Results += (Dots);
Dots2 ++;
}
while (Dots2 <= Dots1);
//Display Error if total words exceeds 40
int Total = NumberWord1 + NumberWord2;
while (Total > 40 || Dots1 < 1 || TotalDots < 40) {
JOptionPane.showMessageDialog(null,"Total Character is over the length \n Please Re-Enter both Words",
"Homework5",JOptionPane.ERROR_MESSAGE);
//User Enter's the 1st word
Word1 = JOptionPane.showInputDialog(null,"Enter First Word",
"Homework5",JOptionPane.QUESTION_MESSAGE);
//Calculate the length of 1st word
NumberWord1 = Word1.length();
//Check Character in Word1
while (NumberWord1 >= 37) {
JOptionPane.showMessageDialog(null,"LengthWord1 = "+""+Word1.length()
+"\n Character in your First Word exceeds 37 character \n Please Re-Enter your First Word",
"Homework5",JOptionPane.ERROR_MESSAGE);
//User Re-Enter's First Word
Word1 = JOptionPane.showInputDialog(null,"Enter First Word",
"Homework5",JOptionPane.QUESTION_MESSAGE);
//Calculate the length of 1st word
NumberWord1 = Word1.length();
}
//User Enter's Second Word
Word2 = JOptionPane.showInputDialog(null,"Enter Second Word", "Homework5",JOptionPane.QUESTION_MESSAGE);
//Calculate the length of 2nd word
NumberWord2 = Word2.length();
//Check Character in Word2
while (NumberWord2 >= 37) {
JOptionPane.showMessageDialog(null,"LengthWord2 = "+""+Word2.length()+"\n Character in your Second Word exceeds 37 character \n Please Re-Enter your Second Word",
"Homework5",JOptionPane.ERROR_MESSAGE);
//User Re-Enter's Second Word
Word2 = JOptionPane.showInputDialog(null,"Enter Second Word",
"Homework5",JOptionPane.QUESTION_MESSAGE);
}
//Re-Calculate Dots
Dots1 = TotalDots - 1 - Word1.length() - Word2.length();
Total = NumberWord1 + NumberWord2;
do {
Results += (Dots);
Dots2++;
}
while(Dots2 <= Dots1);
}
//Displaying Results
JOptionPane.showMessageDialog(null,NumberWord1 + Results + NumberWord2 + "\n"
+ "Length of Word1 = " + "" + Word1.length() + "\n"
+ "Length of Word2 = " + "" + Word2.length()+ "\n"
+ "Length of Dots = " + "" + Dots2,
"Homework5",JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}
}