So I'm in a Java class, and I did all this but the Gpa isnt returning a result, it just returns 0.0 when it gets ran, and for the life of me I cant find the problem, here the code.
Code:import javax.swing.JOptionPane; public class ShowStudent { public static void main(String[] args) { Student oneStudent = new Student(); int showId; int showHours; int showEarned; double showGpa; oneStudent.setidNum(Integer.parseInt(JOptionPane.showInputDialog(null, "ID Number: "))); oneStudent.setcHours(Integer.parseInt(JOptionPane.showInputDialog(null, "Total Credit Hours Earned: "))); oneStudent.setpEarned(Integer.parseInt(JOptionPane.showInputDialog(null, "Total Points Earned: "))); showId = oneStudent.getidNum(); showHours = oneStudent.getcHours(); showEarned = oneStudent.getpEarned(); showGpa = oneStudent.getGpa(); JOptionPane.showMessageDialog(null, "ID Number: " + showId + "\nTotal Credit Hours Earned: " + showHours + "\nTotal Points Earned: " + showEarned + "\nGPA: " + showGpa); } }Code:public class Student { private int idNum; private int cHours; private int pEarned; private double Gpa; public int getidNum() { return idNum; } public int getcHours() { return cHours; } public int getpEarned() { return pEarned; } public double getGpa() { Gpa = cHours/pEarned; return Gpa; } public void setidNum(int showId) { idNum = showId; } public void setcHours(int showHours) { cHours = showHours; } public void setpEarned(int showEarned) { pEarned = showEarned; } public void setGpa(double showGpa) { Gpa = showGpa; } }




Reply With Quote