我正在尝试制作 GPA 计算器。我在两列中有一堆微调器。每个 7 个。我已经放入了要在下拉列表中显示的字符串数组。现在,我想用java编写代码来说明如果用户从下拉列表中选择“四”,那么输入应该被认为是数字4,然后再乘以例如如果用户选择A级,然后乘以与 4. 我该怎么做?我创建了一个阵列适配器,但它不工作。我得到“Nan”作为答案。我查了一下,它说当数字未定义时会显示 Nan。任何帮助,将不胜感激。谢谢!
我应该使用某种 onClickListener,就像我用于按钮一样吗?如果用户选择 A 级,计算机如何知道它必须将等级点等同于 4?
这就是我所做的(这显然是错误的):
if(spinner1.getSelectedItem().equals("A+")) gradepoint1=4.00;
if(spinner1.getSelectedItem().equals("A")) gradepoint1=4.00;
if(spinner1.getSelectedItem().equals("A-")) gradepoint1=3.67;
if(spinner1.getSelectedItem().equals("B+")) gradepoint1=3.33;
if(spinner1.getSelectedItem().equals("B")) gradepoint1=3.00;
if(spinner1.getSelectedItem().equals("B-")) gradepoint1=2.67;
if(spinner1.getSelectedItem().equals("C+")) gradepoint1=2.33;
if(spinner1.getSelectedItem().equals("C")) gradepoint1=2.00;
if(spinner1.getSelectedItem().equals("C-")) gradepoint1=1.67;
if(spinner1.getSelectedItem().equals("D+")) gradepoint1=1.33;
if(spinner1.getSelectedItem().equals("D")) gradepoint1=1.00;
if(spinner1.getSelectedItem().equals("D-")) gradepoint1=0.67;
if(spinner1.getSelectedItem().equals("F")) gradepoint1=0.00;
if(spinner1.getSelectedItem().equals("ABS")) gradepoint1=0.00;