每次我试着运行这个程序,它就会终止,我不知道为什么?我试图让它在接收对话框输入的同时输出选民数据。每次我试着运行这个程序,它就会终止它。我已经玩弄了代码,但似乎无法找出原因。感谢您的帮助。
package voting;
import javax.swing.JOptionPane;
public class VotingData {
public static void main(String[] args) {
new VotingData();
}
VotingData(){
String[] choices = {"M","F"};
int gender = JOptionPane.showOptionDialog(null, "Select M for male and F for female", "Click a button", JOptionPane.DEFAULT_OPTION,
JOptionPane.INFORMATION_MESSAGE, null, choices, choices[0]);
String[] options = {"a","b"};
int age = JOptionPane.showOptionDialog(null, "Select a if you are older than 25 select b if younger", "Click a button", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, null, options, options[0]);
String[] choose = {"Yes","No"};
int ed = JOptionPane.showOptionDialog(null, "Select yes if you graduated college, select no if you did not", "Click a button", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, null, choose, choose[0]);
String[] decide = {"Trump","Biden"};
int president = JOptionPane.showOptionDialog(null, "Select your presidential canidate", "Click a button", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, null, decide, decide[0]);
double totalvoters, femalevoters, malevoters, femalebiden, malebiden, femaletrump, maletrump, femalecollegetrump, femalecollegebiden, u25trump, u25biden, totaltrump, totalbiden, totalcollege, totalnoncollege, u25total, over25total;
{
femalevoters=Double.parseDouble("F");
malevoters=Double.parseDouble("M");
totalvoters=femalevoters+malevoters;
totalbiden=Double.parseDouble("Biden");
totaltrump=Double.parseDouble("Trump");
totalcollege=Double.parseDouble("Yes");
totalnoncollege=Double.parseDouble("No");
u25total=Double.parseDouble("b");
over25total=Double.parseDouble("a");
femalebiden=((totalvoters-malevoters-totaltrump)/totalvoters*100);
femaletrump=((totalvoters-malevoters-totalbiden)/totalvoters*100);
malebiden=((totalvoters-femalevoters-totaltrump)/totalvoters*100);
maletrump=((totalvoters-femalevoters-totalbiden)/totalvoters*100);
femalecollegebiden=((totalvoters-malevoters-totalnoncollege- totaltrump)/totalvoters*100);
femalecollegetrump=((totalvoters-malevoters-totalnoncollege-totalbiden)/totalvoters*100);
u25biden=((totalvoters-over25total-totaltrump)/totalvoters*100);
u25trump=((totalvoters-over25total-totalbiden)/totalvoters*100);
int gender1=0;
while (gender1<20) {
System.out.println(age);
age++;
System.out.println("The total number of voters =" + totalvoters);
System.out.println("The total number of female voters =" + femalevoters);
System.out.println("The total number of male voters =" + malevoters);
System.out.println("The total percent of female Biden supporters =" + femalebiden);
System.out.println("The total percent of female Trump supporters =" + femaletrump);
System.out.println("The total percent of male Biden supporters =" + malebiden);
System.out.println("Thetotal percent of male Trump supporters =" + maletrump);
System.out.println("The total percent of female college educated
Bdien supporters =" + femalecollegebiden);
System.out.println("The total percent of female college edcucated
Trump suppoerters =" + femalecollegetrump);
System.out.println("The total percent of under 25 Biden supporters =" + u25biden);
System.out.println("The total percent of under 25 Trump supporters =" + u25trump);
System.out.println("The total amount of voters for Biden =" + totalbiden);
System.out.println("The total amount of voters for Trump =" + totaltrump);
System.exit(0);
}
}
}
}
1条答案
按热度按时间8ehkhllq1#
六羟甲基三聚氰胺六甲醚。。。给你。
所有的语法错误已经被删除,我已经告诉你的方向,你需要去。
注意:我没有触及您的计算,也没有更改您的输出代码。我只解决了问题中提到的你的问题。
如果您愿意,请向上投票;)