aspose file tools*
The moose likes Beginning Java and the fly likes GPA Program ......... Error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "GPA Program ......... Error" Watch "GPA Program ......... Error" New topic
Author

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

Sultan Aziz
Greenhorn

Joined: Feb 06, 2004
Posts: 4
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

Joined: Mar 05, 2003
Posts: 32
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 ]

- Donny Nadolny<br />The pen is mightier than the sword, and considerably easier to write with.
Mark Vedder
Ranch Hand

Joined: Dec 17, 2003
Posts: 624

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: GPA Program ......... Error