Note that there are some explanatory texts on larger screens.

plurals
  1. POJava: increment user input by 1 for each loop
    primarykey
    data
    text
    <p>I want the program to keep looping until the user inputs -33. For each loop it displays 4 options for the user to vote on. After the user has voted, it increments the value for the painting which the user has voted on by 1 and then goes to the next round.</p> <p>This is the code that I have at the moment and its not really working as I planned:</p> <pre><code>import javax.swing.*; // import swing lib for i/o public class arrraa { static String[] painting = new String[4];//these have been made global and static static int[] votescount = new int[4]; public static void main (String[] args) { // Initialize String Arrays painting[0] = "Mona Lisa";//these have been moved so that it is only called once painting[1] = "Water Lillies"; painting[2] = "The Scream"; painting[3] = "A Young Rembrandt"; // Initialize int Arrays votescount[0] = 0; votescount[1] = 0; votescount[2] = 0; votescount[3] = 0; voteperson(); System.exit(0); } // end method main public static int voteperson() { // Declare String Variables String userinput; userinput = JOptionPane.showInputDialog ("Please tell us which painting you think is the best."+"\n"+ "Vote 1 "+painting[0]+"\n"+ "Vote 2 "+painting[1]+"\n"+ "Vote 3 "+painting[2]+"\n"+ "Vote 4 "+painting[3]); int answer = Integer.parseInt(userinput); System.out.println(answer); while(answer!=-33); { if (answer == 1) { votescount[0] = votescount[0]+1; } else if (answer == 2) { votescount[1] = votescount[1]+1; } else if (answer == 3) { votescount[2] = votescount[2]+1; } else if (answer == 4) { votescount[3] = votescount[3]+1; } else { JOptionPane.showMessageDialog(null, "Vote for one of these four paintings!"); } JOptionPane.showMessageDialog (null, "The current votes are" + "\n" + votescount[0] + " :" + painting[0] + "\n" + votescount[1] + " :" + painting[1] + "\n" + votescount[2] + " :" + painting[2] + "\n" + votescount[3] + " :" + painting[3]); answer++; }//ENDS LOOP return 0; }//ENDS voteperson }//ENDS CLASS </code></pre> <p>Any advice?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload