It is a loop program that counts Yes votes with 'Y', no votes with "N" and to quit is "Q" and after quit is chosen it shows number of yes votes and number of no votes, all in a dialog box. Here it is, when I enter Y, y, N or n it crashes, but Q or q works
import javax.swing.JOptionPane;
public class program05 {
public static void main(String[] args) {
int yes = 0;
int no = 0;
String reply;
char firstChar;
int buttonPressed = 1;
while (buttonPressed != 0) {
reply = JOptionPane.showInputDialog(null,
"Enter 'Y' to vote yes, 'N' to vote no, or 'Q' to quit.");
firstChar = reply.charAt(0);
if (firstChar == 'Y' || firstChar == 'y') {
int yesVotes = Integer.parseInt (reply);
yes += yesVotes;
}
else if (firstChar == 'N' || firstChar == 'n') {
int noVotes = Integer.parseInt (reply);
no += noVotes;
}
else if (firstChar == 'Q' || firstChar == 'q') {
buttonPressed = JOptionPane.showConfirmDialog(null, "Really quit?");
}
}
JOptionPane.showMessageDialog
(null, "Total Yes votes is " + yes + " and total No votes is " + no);
}
}
here is the exception message
Exception in thread "main" java.lang.NumberFormatException: For input string: "y"
at java.lang.NumberFormatException.forInputString(Num berFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:492)
at java.lang.Integer.parseInt(Integer.java:527)
at program05.main(program05.java:26)
Java Result: 1
BUILD SUCCESSFUL (total time: 5 seconds)