Hi I have this code that i've written, I was wondering how I would add 1 to my int[] scores array when a user inputs one of the paintings.
For example: If the user enters "Mona Lisa" it would add 1 to the int scores and it would becomes int[] scores = {1,0,0,0}; and if i did this for "the scream" it would then be int[] scores = {1,0,1,0};
Also if instead of making the user type "Mona Lisa" they could just enter 1, and for the next painting they'd just enter 2...etc
THANKS IN ADVANCE!
/* ***************************************** AUTHOR ******************************************** */ import javax.swing.*; // import the swing library for I/O public class painting { public static void main (String[] param) { vote(); 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 vote() { // 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=1; y<paintings.length; y++) { System.out.println("Vote "+ y + " for " + paintings[y]); } for (int i=0; i<paintings.length; i++) { String painting = JOptionPane.showInputDialog("Which painting would you like to vote for?"); if (paintings[i].equals(painting)) { JOptionPane.showMessageDialog(null, "You voted for " + painting); } if(total.equals(painting)) { for(int z=0; z<paintings.length; z++) System.out.println(scores[z] + paintings[z]); } else { JOptionPane.showMessageDialog(null, "Invalid entry"); } } } }