Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Campbell Ritchie
• Paul Clapham
• Ron McLeod
• Jeanne Boyarsky
• Tim Cooke
Sheriffs:
• Liutauras Vilda
• paul wheaton
• Henry Wong
Saloon Keepers:
• Tim Moores
• Tim Holloway
• Stephan van Hulst
• Carey Brown
• Frits Walraven
Bartenders:
• Piet Souris
• Himai Minh

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

Greenhorn
Posts: 4
• Number of slices to send:
Optional 'thank-you' note:
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));
}
}

Ranch Hand
Posts: 32
• Number of slices to send:
Optional 'thank-you' note:
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 ]

Ranch Hand
Posts: 624
• Number of slices to send:
Optional 'thank-you' note:

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 carry this gun in case a vending machine doesn't give me my fritos. This gun and this tiny ad: free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
Similar Threads