0% found this document useful (0 votes)
59 views6 pages

Java Web Service for GPA Calculation

This document describes a Java web service that calculates a student's grade point average (GPA) based on grades and credits. The web service takes grades and credits as input strings, splits them into arrays, assigns point values to each grade, calculates the total points and credits, and returns the GPA. It first checks that the input is not empty, then iterates through to get total points and credits by parsing the grade/credit arrays and multiplying their values. It returns a string with the total points, total credits, and calculated GPA.

Uploaded by

Muthumanikandan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
59 views6 pages

Java Web Service for GPA Calculation

This document describes a Java web service that calculates a student's grade point average (GPA) based on grades and credits. The web service takes grades and credits as input strings, splits them into arrays, assigns point values to each grade, calculates the total points and credits, and returns the GPA. It first checks that the input is not empty, then iterates through to get total points and credits by parsing the grade/credit arrays and multiplying their values. It returns a string with the total points, total credits, and calculated GPA.

Uploaded by

Muthumanikandan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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

You might also like