0

I am learning web services with NetBeans and did a program for stock price calculation. I need to return 2 values to display price and profit/loss.

But i cant able to return two values. I need to return C variable. Please Help!!.

package test;

import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.ejb.Stateless;


@WebService(serviceName = "Gold")
@Stateless()
public class Gold {
int a,c;


@WebMethod(operationName = "hello")
public String hello(@WebParam(name = "name") String txt) {
    return "Hello " + txt + " !";
}


@WebMethod(operationName = "Calc")
public int Calc(@WebParam(name = "grams") int grams, @WebParam(name = "time") int time) {
    //TODO write your implementation code here:
    if(time>11){
    a=grams*100;
    c=(grams*100-grams*80);
    }
    else if(time<11)
    {
    a=grams*80;
    c=(grams*80-grams*100);
    }

    return a;
}
}
Lewis
  • 70
  • 8
Bharath
  • 15
  • 7

1 Answers1

0

Could you implement something like this:

public class PriceInfo {
  public int Price;
  public int ProfitOrLoss;
}

@WebMethod(operationName = "Calc")
public PriceInfo Calc(@WebParam(name = "grams") int grams, @WebParam(name = "time") int time) {
    //TODO write your implementation code here:
    if(time>11){
    a=grams*100;
    c=(grams*100-grams*80);
    }
    else if(time<11)
    {
    a=grams*80;
    c=(grams*80-grams*100);
    }

    PriceInfo result = new PriceInfo();
    result.Price = a;
    result.ProfitLoss = c;         

    return result;
}

Please double check my code as I am not a java-programmer

Dzianis Yafimau
  • 2,034
  • 1
  • 27
  • 38
  • Now i have no errors in my program. but the output is not as expected. It says "Service invocation threw an exception with message : null; Refer to the server log for more details". – Bharath Jan 27 '16 at 16:08