| | |
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:
Solved Threads: 0
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.
"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.
Java Syntax (Toggle Plain Text)
import javax.swing.JOptionPane; public class GPA { private double gpa = 0.0; private int classNum; private String gradeInput; public GPA() { } public String UserInput(){ gradeInput = JOptionPane.showInputDialog("Enter Grade:"); return gradeInput; } public double inputGrade() { for(classNum = 1; classNum <= 7; classNum++) { UserInput(); if((gradeInput == "Q") || (gradeInput == "q")) gpa = gpa;//its stupposed to stop the loop when you type Q/q //not sure how to make it stop the loop yet else if((gradeInput == "A") || (gradeInput == "a")) gpa = (gpa + 4.0) / 2; else if((gradeInput == "B") || (gradeInput == "b")) gpa = (gpa + 3.0) / 2; else if((gradeInput == "C") || (gradeInput == "c")) gpa = (gpa + 2.0) / 2; else if((gradeInput == "D") || (gradeInput == "d")) gpa = (gpa + 1.0) / 2; else if((gradeInput == "F") || (gradeInput == "f")) gpa = (gpa + 0.0) / 2; } return gpa; } public static void main(String [] args) { GPA runProgram = new GPA(); System.out.print(runProgram.inputGrade()); } }
Last edited by Amurka; Oct 17th, 2007 at 7:56 pm.
Java Syntax (Toggle Plain Text)
import javax.swing.JOptionPane; public class GPA { private double gpa = 0.0; public GPA() { } public String UserInput(){ gradeInput = JOptionPane.showInputDialog("Enter Grade:"); return gradeInput; } public void inputGrade() { for(int classNum = 1; classNum <= 7; classNum++) { String gradeInput= UserInput(); //dont need to use private variable when passing variables if((gradeInput == "Q") || (gradeInput == "q")) classNum=8;//makes classNum<=7 false else if((gradeInput == "A") || (gradeInput == "a")) gpa = (gpa + 4.0) / 2; else if((gradeInput == "B") || (gradeInput == "b")) gpa = (gpa + 3.0) / 2; else if((gradeInput == "C") || (gradeInput == "c")) gpa = (gpa + 2.0) / 2; else if((gradeInput == "D") || (gradeInput == "d")) gpa = (gpa + 1.0) / 2; else if((gradeInput == "F") || (gradeInput == "f")) gpa = (gpa + 0.0) / 2; } } public static void main(String [] args) { GPA runProgram = new GPA(); System.out.print(inputGrade());//dont need to say run program } }
this.love(*);
&hea/rts;
&hea/rts;
@nschessnerd , you better test it before you submiting something or you may be providing wrong solution an waisting your and poster time...
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
Java Syntax (Toggle Plain Text)
import javax.swing.JOptionPane; public class GPA { private double gpa = 0.0; private int classNum; private String gradeInput; public GPA() { } public String UserInput(){ gradeInput = JOptionPane.showInputDialog("Enter Grade:"); return gradeInput; } public double inputGrade() { int end = 0; for(classNum = 1; classNum <= 7; classNum++) { gradeInput = UserInput(); switch(Character.toLowerCase(gradeInput.charAt(0) )) { case 'q' : classNum = 8; break; case 'a': gpa += 4.0; end = classNum; break; case 'b': gpa += 3.0; end = classNum; break; case 'c': gpa += 2.0; end = classNum; break; case 'd': gpa += 1.0; end = classNum; break; case 'f': gpa += 0.0; end = classNum; break; default: break; } // close switch } return gpa/end; } public static void main(String [] args) { GPA runProgram = new GPA(); System.out.print(runProgram.inputGrade()); } }
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
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
![]() |
Similar Threads
- user input into a string (C++)
- Tutorial: User Input: Strings and Numbers [C++] (C++)
- User Input without GUI... Need Guidance (Java)
- Error Checking for user input (Java)
- error checking of user input (C++)
- Creating a GUI that accepts user input help (Java)
- Need Help With Error Checking User Input (C)
- filtering bad user input (Java)
Other Threads in the Java Forum
- Previous Thread: Fraction Calculator
- Next Thread: averages from arrays
| Thread Tools | Search this Thread |
Tag cloud for Java
android api apple applet application applications arguments array arrays automation bank binary bluetooth chat class classes clear client code codesnippet component database db development dice draw ebook eclipse error event exception file formatingtextintooltipjava fractal game givemetehcodez graphics gui helpwithhomework html ide image infinite input integer invokingapacheantprogrammatically j2me jarfile java javaprojects jmf jni jpanel julia linux list loop map method methods mobile mysql netbeans newbie number object openjavafx oracle parameter php print problem program programming project recursion repositories scanner screen scrollbar server set size sms socket sort sorting sql sqlserver state storm string superclass swing test text-file threads time tree windows






