Calculate GPA problems with user input, Help needed

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Oct 2007
Posts: 8
Reputation: Amurka is an unknown quantity at this point 
Solved Threads: 0
Amurka Amurka is offline Offline
Newbie Poster

Calculate GPA problems with user input, Help needed

 
0
  #1
Oct 17th, 2007
My assignment is:
"Write a program that accepts the letter grades for a student, calculates the student's gpa, and prints it out, along with one of the following five messages:
Eligible
Ineligible, taking less than 4 classes
Ineligible, gpa below 2.0
Ineligible, gpa above 2.0 but has F grade (note: gpa >= 2.0)
Ineligible, gpa below 2.0 and has F grade"

To be eligible:
"1. No F's.
2. Minimum 2.0 grade point average (gpa) Note: A = 4.0, B = 3.0, C = 2.0, D = 1.0, F = 0
3. Enrollment in a minimum of four academic classes"

I'm just starting with JAVA and I can't get this to work. As of right now I have given up trying to figure out the eligibility parts and am focusing on just the gpa. Every time I run this program I get the answer 0.0 for the gpa. What in the world am I doing wrong. Remember me = noob. If anyone can help me in the right direction, I'd be very greatful. Also, I can't figure out how to get it to stop the loop when you enter Q or q. And how do you store multiple user input values and use them later. Here is one of my 200000 attempts at this.

  1. import javax.swing.JOptionPane;
  2.  
  3. public class GPA {
  4.  
  5. private double gpa = 0.0;
  6. private int classNum;
  7. private String gradeInput;
  8.  
  9. public GPA() {
  10. }
  11.  
  12. public String UserInput(){
  13. gradeInput = JOptionPane.showInputDialog("Enter Grade:");
  14. return gradeInput;
  15. }
  16.  
  17. public double inputGrade()
  18. {
  19. for(classNum = 1; classNum <= 7; classNum++)
  20. {
  21. UserInput();
  22. if((gradeInput == "Q") || (gradeInput == "q"))
  23. gpa = gpa;//its stupposed to stop the loop when you type Q/q
  24. //not sure how to make it stop the loop yet
  25. else if((gradeInput == "A") || (gradeInput == "a"))
  26. gpa = (gpa + 4.0) / 2;
  27. else if((gradeInput == "B") || (gradeInput == "b"))
  28. gpa = (gpa + 3.0) / 2;
  29. else if((gradeInput == "C") || (gradeInput == "c"))
  30. gpa = (gpa + 2.0) / 2;
  31. else if((gradeInput == "D") || (gradeInput == "d"))
  32. gpa = (gpa + 1.0) / 2;
  33. else if((gradeInput == "F") || (gradeInput == "f"))
  34. gpa = (gpa + 0.0) / 2;
  35. }
  36. return gpa;
  37. }
  38.  
  39. public static void main(String [] args)
  40. {
  41. GPA runProgram = new GPA();
  42. System.out.print(runProgram.inputGrade());
  43. }
  44. }
Last edited by Amurka; Oct 17th, 2007 at 7:56 pm.
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 201
Reputation: nschessnerd is an unknown quantity at this point 
Solved Threads: 8
nschessnerd's Avatar
nschessnerd nschessnerd is offline Offline
Posting Whiz in Training

Re: Calculate GPA problems with user input, Help needed

 
0
  #2
Oct 18th, 2007
  1. import javax.swing.JOptionPane;
  2.  
  3. public class GPA {
  4.  
  5. private double gpa = 0.0;
  6.  
  7. public GPA() {
  8. }
  9.  
  10. public String UserInput(){
  11. gradeInput = JOptionPane.showInputDialog("Enter Grade:");
  12. return gradeInput;
  13. }
  14.  
  15. public void inputGrade()
  16. {
  17. for(int classNum = 1; classNum <= 7; classNum++)
  18. {
  19. String gradeInput= UserInput(); //dont need to use private variable when passing variables
  20. if((gradeInput == "Q") || (gradeInput == "q"))
  21. classNum=8;//makes classNum<=7 false
  22. else if((gradeInput == "A") || (gradeInput == "a"))
  23. gpa = (gpa + 4.0) / 2;
  24. else if((gradeInput == "B") || (gradeInput == "b"))
  25. gpa = (gpa + 3.0) / 2;
  26. else if((gradeInput == "C") || (gradeInput == "c"))
  27. gpa = (gpa + 2.0) / 2;
  28. else if((gradeInput == "D") || (gradeInput == "d"))
  29. gpa = (gpa + 1.0) / 2;
  30. else if((gradeInput == "F") || (gradeInput == "f"))
  31. gpa = (gpa + 0.0) / 2;
  32. }
  33.  
  34. }
  35.  
  36. public static void main(String [] args)
  37. {
  38. GPA runProgram = new GPA();
  39. System.out.print(inputGrade());//dont need to say run program
  40. }
  41. }
didnt test it but try that
this.love(*);
&hea/rts;
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,257
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 493
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: Calculate GPA problems with user input, Help needed

 
0
  #3
Oct 18th, 2007
@nschessnerd , you better test it before you submiting something or you may be providing wrong solution an waisting your and poster time...

  1. import javax.swing.JOptionPane;
  2.  
  3. public class GPA {
  4.  
  5. private double gpa = 0.0;
  6. private int classNum;
  7. private String gradeInput;
  8.  
  9. public GPA() {
  10. }
  11.  
  12. public String UserInput(){
  13. gradeInput = JOptionPane.showInputDialog("Enter Grade:");
  14. return gradeInput;
  15. }
  16.  
  17. public double inputGrade()
  18. {
  19. int end = 0;
  20. for(classNum = 1; classNum <= 7; classNum++)
  21. {
  22. gradeInput = UserInput();
  23.  
  24. switch(Character.toLowerCase(gradeInput.charAt(0) ))
  25. {
  26. case 'q' :
  27. classNum = 8;
  28. break;
  29. case 'a':
  30. gpa += 4.0;
  31. end = classNum;
  32. break;
  33. case 'b':
  34. gpa += 3.0;
  35. end = classNum;
  36. break;
  37. case 'c':
  38. gpa += 2.0;
  39. end = classNum;
  40. break;
  41. case 'd':
  42. gpa += 1.0;
  43. end = classNum;
  44. break;
  45. case 'f':
  46. gpa += 0.0;
  47. end = classNum;
  48. break;
  49. default:
  50. break;
  51. } // close switch
  52.  
  53. }
  54. return gpa/end;
  55. }
  56.  
  57. public static void main(String [] args)
  58. {
  59. GPA runProgram = new GPA();
  60. System.out.print(runProgram.inputGrade());
  61. }
  62. }
I understand that gpa should return everage mark so I ajusted calculation. If I'm wrong please corect it as necessary. The code bellow return gpa, so now you have to think how do you gone find if person had any "F" in the results
Last edited by peter_budo; Oct 18th, 2007 at 3:25 pm.
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 8
Reputation: Amurka is an unknown quantity at this point 
Solved Threads: 0
Amurka Amurka is offline Offline
Newbie Poster

Re: Calculate GPA problems with user input, Help needed

 
0
  #4
Oct 18th, 2007
I tried a switch, but I get getting unexpected type error so gave up with that. Thanks so much, and yes now hmmmm how do you do that 'F' thing, but I think I know a way and if I don't I gotta give it a few trys before I ask for help.
Last edited by Amurka; Oct 18th, 2007 at 3:38 pm.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 8
Reputation: Amurka is an unknown quantity at this point 
Solved Threads: 0
Amurka Amurka is offline Offline
Newbie Poster

Re: Calculate GPA problems with user input, Help needed

 
0
  #5
Oct 18th, 2007
I got it all to work...Thanks for the help Peter_budo.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC