- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我无法找出我的程序的问题,非常感谢任何帮助!不幸的是,我是一名初学者程序员......当我运行该程序时,它会正确要求类(class)数量、学分和成绩,但它会忽略输入的学分,只给出字母成绩的正常值。最后它还写着“你的 GPA 是 0.0”,但这显然是不正确的。再次感谢!
public class QualityPoints
{
public static void main(String[] args)
{
// Needed variables
String grade;
int totalCredits = 0;
int totalCreditsEarned = 0;
int credits;
int classes;
double gpa;
double number=0;
String greeting = "This program will calculate your GPA.";
JOptionPane.showMessageDialog(null, greeting, "GPA Calculator", 1);
classes = Integer.parseInt(JOptionPane.showInputDialog(null, "Enter the number of classes you are taking"));
//Loop that ends once the student has put information in on all his classes
for(int count = 0; count < classes; count++)
{
credits = Integer.parseInt(JOptionPane.showInputDialog(null, "How many credit was this class?:"));
//reads the letter grade using the String Grade prompt
// gathers input from user and assigns a string into JOptionPane
grade = JOptionPane.showInputDialog(null, "Enter letter grade: ",
"Quality Points Converter", JOptionPane.INFORMATION_MESSAGE);
// calls separate method (computeQualityPoints) using parameter grade
if (!grade.equalsIgnoreCase("a") && !grade.equalsIgnoreCase("a-")
&& !grade.equalsIgnoreCase("b+") && !grade.equalsIgnoreCase("b")
&& !grade.equalsIgnoreCase("b-") && !grade.equalsIgnoreCase("c+")
&& !grade.equalsIgnoreCase("c") && !grade.equalsIgnoreCase("c-")
&& !grade.equalsIgnoreCase("d+") && !grade.equalsIgnoreCase("d")
&& !grade.equalsIgnoreCase("d-") && !grade.equalsIgnoreCase("f")) {
JOptionPane.showMessageDialog(null, "Invalid grade entered");
} else {
JOptionPane.showMessageDialog(null, "You received "
+ computeQualityPoints(grade) + " quality points");
computeQualityPoints(grade);
}
//algorithm for finding the GPA
totalCredits += credits;
totalCreditsEarned += (credits * number);
}
//for loop ends
//GPA is calculated for all the students classes
gpa = totalCreditsEarned / totalCredits;
JOptionPane.showMessageDialog(null, "Your GPA is: " + gpa);
}
/**
* Uses the letter grade given as the parameter to compute quality points
* received, thus displaying quality points as the output
*
* @param grade
* @return JOptionPane message box with the number of quality points, given
* a valid letter grade.
*/
public static double computeQualityPoints(String grade) {
/**
* If/else statments providing the message attached to the output
* corresponding to the grade
*/
if (grade.equalsIgnoreCase("a")) {
return 4.0;
}
if (grade.equalsIgnoreCase("a-")) {
return 3.7;
}
if (grade.equalsIgnoreCase("b+")) {
return 3.3;
}
if (grade.equalsIgnoreCase("b")) {
return 3.0;
}
if (grade.equalsIgnoreCase("b-")) {
return 2.7;
}
if (grade.equalsIgnoreCase("c+")) {
return 2.3;
}
if (grade.equalsIgnoreCase("c")) {
return 2.0;
}
if (grade.equalsIgnoreCase("c-")) {
return 1.7;
}
if (grade.equalsIgnoreCase("d+")) {
return 1.3;
}
if (grade.equalsIgnoreCase("d")) {
return 1.0;
}
if (grade.equalsIgnoreCase("d-")) {
return 0.7;
}
if (grade.equalsIgnoreCase("f")) {
return 0.0;
}
return 0.0;
}
}
最佳答案
totalCreditsEarned += (credits * number);
number
仍为 0.0
,这意味着 totalCreditsEarned
和 gpa
也将保持为 0.0
>.
我怀疑
computeQualityPoints(grade);
您忽略返回值的地方应该是
number = computeQualityPoints(grade);
(至少我假设这就是 number
应该包含的内容)
关于Java GPA 计算器问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33887334/
void fillQueueWithStudents(Queue *q) { int counter = 1; char answer = 'Y'; //this signifies th
我在 JSP 上做了一个项目,通过 MySQL 数据库根据分数计算 GPA(平均绩点)。这是我的公式: sb=con.prepareStatement("select round((((score)/
为了更详细地说明我正在处理的问题,确切的任务是: 编写一个程序,计算平均值、最小值、最大值和 所有学生的平均 GPA。首先,你的程序会读入学生记录 (姓名和 GPA)并确定文件中学生记录的数量。毕竟
我可以制作一个表格来显示每个部门的 GPA,但我不知道如何让它只显示 GPA 最高的部门。 我的查询是: SELECT avg(grade) as GPA, deptID from tblStuden
package gpatogradecalculator; import java.util.Scanner; public class GPAtoGradeCalculator { publ
已关闭。此问题需要 debugging details 。目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and the
到目前为止,这是我的代码(已更新): import java.util.Scanner; public class gpa { public static void main(String[]
这里是 Java 初学者。所以我对如何制作它感到困惑,所以如果用户输入是“A+”,我将得到 4.0 并且不会更高?类似地,对于“F”,我想让 F、F-、F+ 的结果都是 0.0 gpa。我想要么为字母
已关闭。此问题需要 debugging details 。目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and the
我的主类中有这段代码。我的问题是,GPA 是用总分除以类(class)来计算的。它没有给我完整的号码。 EX,如果总数为 14,类(class)为 4,则为 3.5,我的代码只给我 3.0。有谁知道为
所以这段代码的整个目标是计算一个学期的 GPA。它要求用户提供学期名称(即 2014 年秋季)、类(class)名称、学分和成绩。它将这些信息列出到一个文本文件中,并计算 GPA。 我似乎不知道如何做
我无法找出我的程序的问题,非常感谢任何帮助!不幸的是,我是一名初学者程序员......当我运行该程序时,它会正确要求类(class)数量、学分和成绩,但它会忽略输入的学分,只给出字母成绩的正常值。最后
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 8 年前。 Improve th
这个问题已经有答案了: How do I compare strings in Java? (23 个回答) 已关闭 8 年前。 GPA计算器 我知道那里有类似的线程,但我见过的没有一个遇到我遇到的问
我想根据成绩和学分计算每个学生的 GPA。我已经执行了这样的事情 SET GPA=(SELECT((t.grade*c.credits)/c.credits) FROM Student s, Take
我在连接这个表格上的表格以获得单一结果时遇到了一些问题。计算 GPA 的方法如下: 获取每门类(class)的平均成绩。 将每个平均值乘以该类(class)的学分数。 添加 2 的结果。 将结果除以
我正在尝试创建一个表单,要求用户输入姓名、GPA 和电话号码。我需要帮助来验证 GPA 是否为 0 到 4 之间的数字,包括成绩后最多两位小数。我不知道从哪里开始!
我是 JavaScript 初学者。在这里,我无法弄清楚为什么我的代码没有读取我输入的值,尽管我找不到代码中的任何错误。有什么有用的建议来编辑我的代码以修复错误吗? function gpacalc(
出于某种原因,我的程序在计算 GPA 平均值时出错。如果我输入 4.0 3 次,那么它说平均 GPA 是 3.0 但应该是 4.0。有人可以帮我找到问题吗? //variables double gp
家庭作业问题。我需要遍历一系列字典以获得最高的 gpa 并打印学生的名字和姓氏。我在访问字典条目的 gpa 字段时遇到问题。 // Task 6 var highestGPA = 0.0 var st
我是一名优秀的程序员,十分优秀!