Software is being developed by a university that displays SGPA of your current semester. You are given the task to develop a module that calculates the SGPA with respect to the secured grade points corresponding to given number of credits in each subject. The credits for the courses are: Graphics: 2, PPS: 4, JAVA: 3, Chemistry: 3, English: 2, Technical Skills: 1.5, Data Structures: 4 Complete your Module by displaying the SGPA of current semester.
/* Caluculating */
import java.util.*;
class SGPA_Cal_S_2A
{
public static void main(String[] args)
{
Scanner s = new Scanner(System.in);
double SGPA,total=0,sum=0;
int gp=0,i;
String grade;
String subjects[]={"Graphics","PPS","JAVA","Chemistry","English","TechnicalSkills","Data Structures"};
double Credits[]={2,4,3,3,2,1.5,4};
for(i=0;i<subjects.length;i++)
{
System.out.print("Enter "+subjects[i]+" Grade : ");
grade = s.next();
switch(grade)
{
case "A+":gp=10; break;
case "A": gp=9; break;
case "B": gp=8; break;
case "C": gp=7; break;
case "D": gp=6; break;
case "E": gp=5; break;
case "F": gp=0; break;
default: System.out.println("Wrong Grade.");
i--;
}
if(gp==0)
{
break;
}
total += gp * Credits[i];
sum += Credits[i];
}
if(gp==0)
{
System.out.println("Student Failed in Exam");
}
else
{
SGPA = total/sum;
System.out.println("SGPA is : "+String.format("%.2f",SGPA));
}
}
}
Comments
Post a Comment