Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

GPA Program ......... Error

 
Sultan Aziz
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In this program i want to enter 2 value one for GRADE ( A+ B C ....) another for Credit Hours. And calculate the GPA.
this entrey for 5 Subject
the problem here when i enter the first subject directly calculate the GPA for one subject

class GPA{
public static void main(String args[]){
double sum=0;
int crd=0,i;
int m=3;
for(i=0;i<m;i++){
String g=(args[0]);
int c=Integer.parseInt(args[1]);
if(g.equals("A+")){
sum=sum+(4*c);
crd=crd+c;}

else if(g.equals("A")){
sum=sum+(3.75*c);
crd=crd+c;}

else if(g.equals("B+")){
sum=sum+(3.5*c);
crd=crd+c;}

else if(g.equals("B")){
sum=sum+(3*c);
crd=crd+c;}

else if(g.equals("C+")){
sum=sum+(2.5*c);
crd=crd+c;}

else if(g.equals("C")){
sum=sum+(2*c);
crd=crd+c;}

else if(g.equals("D+")){
sum=sum+(1.5*c);
crd=crd+c;}

else if(g.equals("D")){
sum=sum+(1*c);
crd=crd+c;}

else if(g.equals("F")){
sum=sum+(0*c);
crd=crd+c;}
else
System.out.println("Chek Your Grade");
}
System.out.println("Your GPA is "+(sum/crd));
}
}
 
Donny Nadolny
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello. You want to calculate the GPA for 5 subjects, correct? All you are doing is getting the first and second argument passed to your program (String g = (args [0]); int c = Integer.parseInt (args [1]); ) . What you need to do is use a loop like:

If you need more help or if I wasn't clear enough, just reply and I'll try my best.
Edit: Some code was accidentally interpreted as an emoticon, changed spacing.
[ February 09, 2004: Message edited by: Donny Nadolny ]
 
Mark Vedder
Ranch Hand
Posts: 624
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Donny Nadolny:
Edit: Some code was accidentally interpreted as an emoticon, changed spacing.
[ February 09, 2004: Message edited by: Donny Nadolny ]

FYI, another thing you can do when that happens is to check the "Disable smilies in this post" option in the Options section below the Smilies and UBB code lists.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic