You are on page 1of 6

|SOA Lab

December 22, 2015|4:30:43 PM

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")
public String GPAFinder(@WebParam(name = "Grades") String Grades, @WebParam(name = "Credits")
String Credits) {
if((Grades.isEmpty()==false)&&(Credits.isEmpty()==false))
{
int totalPoints=0;
int totalCredits=0;
float gpa=0.0f;
// get all Grades & store into 1D array
String[] gs=Grades.split("[ ,]");
1

|SOA Lab

December 22, 2015|4:30:43 PM

// get all Credits & store into 1D array


String[] cs=Credits.split("[ ,]");
// calculating total credits
for(int i=0;i<cs.length;i++)
{
tc.add(cs[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"))
{
tp.add(10);
}
else if(gs[i].equalsIgnoreCase("a"))
{
tp.add(9);
}
else if(gs[i].equalsIgnoreCase("b"))
{
tp.add(8);
2

|SOA Lab

December 22, 2015|4:30:43 PM

}
else if(gs[i].equalsIgnoreCase("c"))
{
tp.add(7);
}
else if(gs[i].equalsIgnoreCase("d"))
{
tp.add(6);
}
else if(gs[i].equalsIgnoreCase("e"))
{
tp.add(5);
}
else
{
tp.add(0);
}
}
// 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

December 22, 2015|4:30:43 PM

2. OUTPUT

|SOA Lab

December 22, 2015|4:30:43 PM

2.1 GPA RESULT