我正在尝试创建一个 Java 代码来计算某些画作的投票。我想收集用户投票的内容并将其添加到运行总数中,以便在每个用户投票后打印总票数。
到目前为止,这是我的代码:
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].equals(vote))
{
JOptionPane.showMessageDialog(null, "You voted for " + vote);
paintings[i] + 1 = scores[i];
for(int z=0; z<paintings.length; z++)
System.out.println(scores[z] + " " + paintings[z]);
}
if(total.equals(vote))
{
}
else
{
JOptionPane.showMessageDialog(null, "Invalid entry");
}
}
}
我想要这样说用户投票'蒙娜丽莎'这会将'1'添加到'int []分数'中的第一个整数?我该怎么做?
谢谢