Question: I need help asap I am making a webbase calcualtor ( using spring mvc , maven on intelliJ ) I need help on A only
I need help asap
I am making a webbase calcualtor using spring mvc maven on intelliJ
I need help on A only expression because when I run it it is still asking me to enter something in input B
this is my controller
package com.Junhyeok.webcalculator;
import org.springframework.stereotype.Controller;
import org.springframework.uiModel;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
@Controller
public class WebCalculatorController
This method handles GET requests to the root URL and displays the calculator form.
@GetMapping
public String showCalculator
return "calculator";
@PostMappingcalculate
public ModelAndView calculate
@RequestParaminputA double inputA,
@RequestParamvalue "inputB", required false Double inputB,
@RequestParamoperation String operation,
Model model
double result;
switch operation
case "add":
result inputA inputB;
break;
case "subtract":
result inputA inputB;
break;
case "multiply":
result inputA inputB;
break;
case "division":
result inputA inputB;
break;
case "sin":
result Math.sininputA;
break;
case "cos":
result Math.cosinputA;
break;
case "tan":
result Math.taninputA;
break;
case "factorial":
result factorialint inputA;
break;
case "power":
result Math.powinputA inputB;
break;
case "log":
result Math.loginputA Math.loginputB;
break;
case "root":
result Math.powinputA inputB;
break;
case "equal":
result inputA inputB : ;
break;
default:
throw new IllegalArgumentExceptionInvalid operation: operation;
model.addAttributeresult result;
model.addAttributeinputA inputA;
if inputB null
model.addAttributeinputB inputB;
model.addAttributeoperation operation;
ModelAndView modelAndView new ModelAndViewcalculator "model", model;
return modelAndView;
private double factorialdouble inputA
if inputA
return ;
else
return inputA factorialinputA ;
and this is my html
Web Calculator
Result:
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
