Hello - I am a brand new at Java and I am having a hard time with a program I have to turn in tomorrow. I can not get the 'Q' option to work and the loop goes on forever. I've tried to go over the tutorials but when I change it from here I then get compiling issues... Can someone explain what I've done wrong?
[code=java]
import javax.swing.JOp tionPane;
public class LloydPage_Assig nment5 {
public static void main (String [] args) {
// Enter Y to vote yes
// Enter N to vote no
// Enter Q to quit voting
int quitVote = 0;
int yesVote = 0;
int noVote = 0;
// charAt looks at number in parenthesis, returns char at that location
// within string (the first character is at location 0)
// firstChar is going to be 'Y' or 'N' or 'Q' etc.
// Essentially it is a way to make a string into a char so that you may use string function
String reply1 = JOptionPane.sho wInputDialog
(null, "Enter 'Y' to vote yes, 'N' to vote no, or 'Q' to quit voting");
char userVote = reply1.charAt(0 );
// If the user enters Y or y then add 1 to the number of yes votes
do {
yesVote = yesVote + 1;
reply1 = JOptionPane.sho wInputDialog
(null, "Enter 'Y' to vote yes, 'N' to vote no, or 'Q' to quit voting");
userVote = reply1.charAt(0 );
} while ((userVote == 'Y') || (userVote == 'y'));
// If the user enters N or n then add 1 to the number of no votes
do {
noVote = noVote + 1;
reply1 = JOptionPane.sho wInputDialog
(null, "Enter 'Y' to vote yes, 'N' to vote no, or 'Q' to quit voting");
userVote = reply1.charAt(0 );
} while ((userVote == 'N') || (userVote == 'n'));
// If the user enters any variable other than Y||y, N||n, Q||q then ignore vote
do {
reply1 = JOptionPane.sho wInputDialog
(null, "Enter 'Y' to vote yes, 'N' to vote no, or 'Q' to quit voting");
userVote = reply1.charAt(0 );
} while ((userVote != 'Y') || (userVote != 'y') || (userVote != 'N') || (userVote != 'n') || (userVote != 'Q') || (userVote != 'q'));
// If the user enters Q or q then
// use a showConfirmDial og box
// to ask if they really want to quit
do {
quitVote = JOptionPane.sho wConfirmDialog
(null, "Are you sure you wish to Quit?");
} while ((userVote == 'Q') || (userVote == 'q'));
// Otherwise the loop ends and the totals must be shown in a
// showMessageDial og box
do {
JOptionPane.sho wMessageDialog( null, "The total is number of Yes votes is " + yesVote + "\n The total is number of No votes is " + noVote);
} while (quitVote == JOptionPane.YES _OPTION);
}
}[/code]
[code=java]
import javax.swing.JOp tionPane;
public class LloydPage_Assig nment5 {
public static void main (String [] args) {
// Enter Y to vote yes
// Enter N to vote no
// Enter Q to quit voting
int quitVote = 0;
int yesVote = 0;
int noVote = 0;
// charAt looks at number in parenthesis, returns char at that location
// within string (the first character is at location 0)
// firstChar is going to be 'Y' or 'N' or 'Q' etc.
// Essentially it is a way to make a string into a char so that you may use string function
String reply1 = JOptionPane.sho wInputDialog
(null, "Enter 'Y' to vote yes, 'N' to vote no, or 'Q' to quit voting");
char userVote = reply1.charAt(0 );
// If the user enters Y or y then add 1 to the number of yes votes
do {
yesVote = yesVote + 1;
reply1 = JOptionPane.sho wInputDialog
(null, "Enter 'Y' to vote yes, 'N' to vote no, or 'Q' to quit voting");
userVote = reply1.charAt(0 );
} while ((userVote == 'Y') || (userVote == 'y'));
// If the user enters N or n then add 1 to the number of no votes
do {
noVote = noVote + 1;
reply1 = JOptionPane.sho wInputDialog
(null, "Enter 'Y' to vote yes, 'N' to vote no, or 'Q' to quit voting");
userVote = reply1.charAt(0 );
} while ((userVote == 'N') || (userVote == 'n'));
// If the user enters any variable other than Y||y, N||n, Q||q then ignore vote
do {
reply1 = JOptionPane.sho wInputDialog
(null, "Enter 'Y' to vote yes, 'N' to vote no, or 'Q' to quit voting");
userVote = reply1.charAt(0 );
} while ((userVote != 'Y') || (userVote != 'y') || (userVote != 'N') || (userVote != 'n') || (userVote != 'Q') || (userVote != 'q'));
// If the user enters Q or q then
// use a showConfirmDial og box
// to ask if they really want to quit
do {
quitVote = JOptionPane.sho wConfirmDialog
(null, "Are you sure you wish to Quit?");
} while ((userVote == 'Q') || (userVote == 'q'));
// Otherwise the loop ends and the totals must be shown in a
// showMessageDial og box
do {
JOptionPane.sho wMessageDialog( null, "The total is number of Yes votes is " + yesVote + "\n The total is number of No votes is " + noVote);
} while (quitVote == JOptionPane.YES _OPTION);
}
}[/code]
Comment