/* ***************************************** AUTHOR ******************************************** */ import javax.swing.*; // import the swing library for I/O import java.util.*; public class painting { public static void main (String[] param) { Gallery(); System.exit(0); } // END main /* *************************************************** Define some commands of our own to use above *************************************************** */ /* *************************************************** Set up an array containing animals then find one asked for by the user */ public static void Gallery() { // Declare variables // String total = "-33"; String[] paintings = {"Mona Lisa","Water Lilies","The Scream","A Young Rembrandt"}; int[] scores = {0,0,0,0}; String searchKey; //the thing looked for // //now can get an answer quickly without calculating just looking it up for (int y=0; y<paintings.length; y++) { System.out.println("Vote "+ (y+1) + " for " + paintings[y]); } for (int i=0; i<paintings.length; i++) { String vote = JOptionPane.showInputDialog("Which painting would you like to vote for?"); if (paintings[i].equalsIgnoreCase(vote)) { JOptionPane.showMessageDialog(null, "You voted for " + vote); scores[i]++; for(int z=0; z<paintings.length; z++) System.out.println(scores[z] + " " + paintings[z]); } else if(total.equals(vote)) { JOptionPane.showMessageDialog(null, "You have chosen to exit this program, will now close"); System.exit(0); } else { JOptionPane.showMessageDialog(null, "Invalid entry"); } } } }
My code works perfectly for the first entry but if i enter the same painting twice it seems to skip this part of the code
and just says "invalid entry".if (paintings[i].equalsIgnoreCase(vote)) { JOptionPane.showMessageDialog(null, "You voted for " + vote); scores[i]++; for(int z=0; z<paintings.length; z++) System.out.println(scores[z] + " " + paintings[z]); }
Any ideas?
Thanks