You are on page 1of 6

# |SOA Lab

## 2. GPA CALCULATION USING JAVA WEB SERVICE

1. SOURCE CODE
package gpa;
import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import java.util.*;
@WebService(serviceName = "GPA")
public class GPA {
ArrayList tp=new ArrayList();
ArrayList tc=new ArrayList();
@WebMethod(operationName = "GPAFinder")
String Credits) {
{
int totalPoints=0;
int totalCredits=0;
float gpa=0.0f;
// get all Grades & store into 1D array
1

|SOA Lab

## // get all Credits & store into 1D array

String[] cs=Credits.split("[ ,]");
// calculating total credits
for(int i=0;i<cs.length;i++)
{
totalCredits+=Integer.parseInt(cs[i]);
}
// convert all grades to grade points & store into int[] array
for(int i=0;i<gs.length;i++)
{
if(gs[i].equalsIgnoreCase("s"))
{
}
else if(gs[i].equalsIgnoreCase("a"))
{
}
else if(gs[i].equalsIgnoreCase("b"))
{
2

|SOA Lab

## December 22, 2015|4:30:43 PM

}
else if(gs[i].equalsIgnoreCase("c"))
{
}
else if(gs[i].equalsIgnoreCase("d"))
{
}
else if(gs[i].equalsIgnoreCase("e"))
{
}
else
{
}
}
// GPA calculation process
for(int i=0;i<tp.size();i++)
{
// total points calculation
3

|SOA Lab

## December 22, 2015|4:30:43 PM

totalPoints+=(Integer.parseInt(tp.get(i).toString()))*(Integer.parseInt(tc.get(i).toString()));
}
tp.clear();
tc.clear();
// final GPA calculation
gpa=(float)totalPoints/(float)totalCredits;
String i1="Total Points Earned\t: "+totalPoints+"\n";
String i2="Total Credits Earned\t: "+totalCredits+"\n";
String info=i1+i2+"\n";
return info+"Ur GPA is : "+String.valueOf(gpa);
}
else
return "Input is empty!plz submit the Grades and Credits ";
}
}

|SOA Lab

2. OUTPUT

|SOA Lab