Advertisement
Guest User

Untitled

a guest
Apr 26th, 2015
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. package example;
  2.  
  3.  
  4. import javax.ws.rs.GET;
  5. import javax.ws.rs.Path;
  6. import javax.ws.rs.Produces;
  7. import javax.ws.rs.QueryParam;
  8. import javax.ws.rs.core.MediaType;
  9.  
  10. @Path("calculator")
  11. public class Calculator {
  12. @GET
  13. @Path("squareRoot")
  14. @Produces(MediaType.APPLICATION_JSON)
  15. public Result squareRoot(@QueryParam("input") double input){
  16. Result result = new Result("Square Root");
  17. result.setInput(input);
  18. result.setOutput(Math.sqrt(result.getInput()));
  19. return result;
  20. }
  21.  
  22. @GET
  23. @Path("square")
  24. @Produces(MediaType.APPLICATION_JSON)
  25. public Result square(@QueryParam("input") double input){
  26. Result result = new Result("Square");
  27. result.setInput(input);
  28. result.setOutput(result.getInput()*result.getInput());
  29. return result;
  30. }
  31.  
  32. static class Result{
  33. double input;
  34. double output;
  35. String action;
  36.  
  37. public Result(){}
  38.  
  39. public Result(String action) {
  40. this.action = action;
  41. }
  42.  
  43. public String getAction() {
  44. return action;
  45. }
  46.  
  47. public void setAction(String action) {
  48. this.action = action;
  49. }
  50.  
  51. public double getInput() {
  52. return input;
  53. }
  54.  
  55. public void setInput(double input) {
  56. this.input = input;
  57. }
  58.  
  59. public double getOutput() {
  60. return output;
  61. }
  62.  
  63. public void setOutput(double output) {
  64. this.output = output;
  65. }
  66. }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement