題目如下
編寫圓類,實現圓形周長、面積的計算。
設計網頁,在一個文本框中輸入圓的半徑,點擊計算按鈕,使用javabean動作在頁面中輸出圓的半徑、周長、面積。
建立.java文件和.jsp文件
j2.jsp 代碼
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>
<body>
<jsp:useBean id="count" class="data.circle" scope="request" />
<jsp:setProperty property="radius" name="count" param="radius" />
<jsp:setProperty property="perimeter" name="count" param="radius" />
<jsp:setProperty property="area" name="count" param="radius" />
<form action="j2.jsp" method="post">
請輸入半徑:<input name="radius" type="text" size="6"><br>
<input type="submit" value="計算"> <br>
半徑:<jsp:getProperty name="count" property="radius" /><br>
周長:<jsp:getProperty name="count" property="perimeter" /><br>
面積:<jsp:getProperty name="count" property="area" /><br>
</form>
</body>
</html>
public class circle {
int radius;
double perimeter,area;
public int getRadius() {
return radius;
}
public void setRadius(int radius) {
this.radius = radius;
}
public double getPerimeter()
{
return perimeter;
}
public void setPerimeter(double perimeter) {
this.perimeter=Math.PI * 2 * radius;
}
public double getArea()
{
return area;
}
public void setArea(double area) {
this.area=Math.PI * radius* radius;
}
}
以上。博客小白,希望可以和各位大佬一起探討。
在學校正在學習java web 也希望通過這種方式記錄一下吧!
有問題留言哦!