Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Use Case System User 1. Display Area Calculator Form 2. Enters Height and Width

ID: 3884635 • Letter: U

Question

Use Case

System                                   User

1. Display Area Calculator Form

2. Enters Height and Width values, then presses submit button

3. Validates data [ALT-1]

4. Displays Area Calculator Page showing entered height and width and calculated area •

End of Use Case

Alternative

Flow [ALT-1] 4. Displays Area Calculator Page showing an error message indicating user entered invalid data

Specifications

Student Identifier: aaannn, where • aaa – your initials • MAM327 – last 3 digits of your student id Project

Name: _P1_AreaCalculator

Package   prefix :edu.metrostate.ics425.p1.studentIdentifier Class Name: AreaCalculatorBean –

note: must be a JavaBean with the following properties

Name Type Access Description

height int Read/Write Height Value

width int Read/Write Width Value

area int Read Only Calculated Area

Class Name: AreaCalculatorServlet

JSP Filename: AreaCalculator.jsp

Javadoc All public methods must have meaningful Javadoc comments.

Explanation / Answer

AreaCalculator.jsp

package bean;

public class AreaCalculator {

private double first;

private double second;

private char op='+';

private double res;

public double getFirst() {

return first;

}

public void setFirst(double first) {

this.first = first;

}

public double getSec() {

return second;

}

public void setSec(double second) {

this.second = second;

}

public char getOp() {

return op;

}

public void setOp(char op) {

this.op = op;

}

public double getRes() {

return res;

}

public void setRes(double res) {

this.res = res;

}

public void calc(){

switch(this.op){

case'+':{

this.res=this.first+this.second;

break;

}

case'-':{

this.res=this.first-this.second;

break;

}

case'*':{

this.res=this.first*this.second;

break;

}

case'/':{

if(this.second==0)

{

throw new RuntimeException("Dividend cannot be 0");

}

this.res=this.first/this.second;

break;

}

default:

throw new RuntimeException("Sorry, the input op is illegal!");

}

}

}

index.html

<html>

<head>

</head>

<body>

<jsp:useBean id="AreaCalculator" class="bean.AreaCalculator">

</jsp:useBean>

<jsp:setProperty name="AreaCalculator" property="*" />

<%

AreaCalculator.calc();

%>

<br />

<hr>

<br /> The calculation is:

<jsp:getProperty name="AreaCalculator" property="first" />

<jsp:getProperty name="AreaCalculator" property="op" />

<jsp:getProperty name="AreaCalculator" property="second" />

=

<jsp:getProperty name="AreaCalculator" property="res" />

<br />

<hr>

<br />

<form action="/calculator/index.jsp" method="post"

style="text-align: center">

<table border="1" width="50%">

<tr>

<td colspan="2">Area calculator</td>

<td></td>

</tr>

<tr>

<td>The first parameter</td>

<td><input type="text" name="first">

</td>

</tr>

<tr>

<td>Operator</td>

<td><select name="op">

<option value="+">+</option>

<option value="-">-</option>

<option value="*">*</option>

<option value="/">/</option>

</select></td>

</tr>

<tr>

<td>Second parameters</td>

<td><input type="text" name="second">

</td>

</tr>

<tr>

<td colspan="2"><input type="submit" value="Calculation">

</td>

</tr>

</table>

</form>

</body>

</html>

Rate an upvote......Thankyou

Hope this helps......

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote