What I'm bad at is the dialog box part. This is the code Ive come up with... if you see a way to improve what im thinkng of.... post it please.
Program should....
1. Ask user to type in a sentence, using JOptionPane.sho wInputDialog().
2. The program will scan each letter in the string and count how many times the upper case letter 'E' appears, and how many times the lower case letter 'e' appears.
3. Using a JOptionPane.sho wInputDialog(), tell the user how many upper and lower case e's were in the string.
4. Repeat this process until the user types the word 'Stop'
import javax.swing.*;
public class Project0 {
public static void main (String args[]) {
String line = JOptionPane.sho wInputDialog("E nter a line of text:");
// Checks if input has minimum of 1 character //if (line.length() == 0) // System.exit(0);
if (line.length() !=0 || line.length() ==0 ){ // If input is 'Stop' (case sensitivite) // program will terminate.
if(line.length( ) == 4 && line.charAt(0) == 83 && line.charAt(1) == 116 && line.charAt(2) == 111 && line.charAt(3) == 112 ) System.exit(0);
} // End check for "Stop" input
JOptionPane.sho wMessageDialog( null, "Your string contains " + uppercaseCount( line) + " uppercase letters 'E' and " + lowercaseCount( line) + " lowercase letters 'e'.");
} //end main // This method goes through the input "line" character by character // and keeps count of which are _UPPERCASE_ letters
}
}
}
// using charAt to cycle through each letter public static int uppercaseCount( String line)
{ int upperCount = 0;
for ( int i = 0; i < line.length(); i++ ) {
char x = line.charAt(i);
if ( x == 69 ) { upperCount++;
} //end if()
} //end loop
return upperCount; } //end uppercaseCount
public static int lowercaseCount( String line) {
int lowerCount = 0;
for ( int i = 0; i < line.length(); i++ ) {
char x = line.charAt(i);
if ( x == 101 ) { lowerCount++; } //end if()
} //end loop
return lowerCount; } //end uppercaseCount
} //end class
}
ehh it didnt come out looking clean here... but put it on eclipse or jdk... i think it works? oh and got to use that number system instead of just char 'e' string, etc.
thanks whomever understands this.
Program should....
1. Ask user to type in a sentence, using JOptionPane.sho wInputDialog().
2. The program will scan each letter in the string and count how many times the upper case letter 'E' appears, and how many times the lower case letter 'e' appears.
3. Using a JOptionPane.sho wInputDialog(), tell the user how many upper and lower case e's were in the string.
4. Repeat this process until the user types the word 'Stop'
import javax.swing.*;
public class Project0 {
public static void main (String args[]) {
String line = JOptionPane.sho wInputDialog("E nter a line of text:");
// Checks if input has minimum of 1 character //if (line.length() == 0) // System.exit(0);
if (line.length() !=0 || line.length() ==0 ){ // If input is 'Stop' (case sensitivite) // program will terminate.
if(line.length( ) == 4 && line.charAt(0) == 83 && line.charAt(1) == 116 && line.charAt(2) == 111 && line.charAt(3) == 112 ) System.exit(0);
} // End check for "Stop" input
JOptionPane.sho wMessageDialog( null, "Your string contains " + uppercaseCount( line) + " uppercase letters 'E' and " + lowercaseCount( line) + " lowercase letters 'e'.");
} //end main // This method goes through the input "line" character by character // and keeps count of which are _UPPERCASE_ letters
}
}
}
// using charAt to cycle through each letter public static int uppercaseCount( String line)
{ int upperCount = 0;
for ( int i = 0; i < line.length(); i++ ) {
char x = line.charAt(i);
if ( x == 69 ) { upperCount++;
} //end if()
} //end loop
return upperCount; } //end uppercaseCount
public static int lowercaseCount( String line) {
int lowerCount = 0;
for ( int i = 0; i < line.length(); i++ ) {
char x = line.charAt(i);
if ( x == 101 ) { lowerCount++; } //end if()
} //end loop
return lowerCount; } //end uppercaseCount
} //end class
}
ehh it didnt come out looking clean here... but put it on eclipse or jdk... i think it works? oh and got to use that number system instead of just char 'e' string, etc.
thanks whomever understands this.
Comment