码迷,mamicode.com
首页 > Web开发 > 详细

Class.jsp

时间:2019-03-27 21:30:01      阅读:173      评论:0      收藏:0      [点我收藏+]

标签:函数   tle   默认构造函数   pre   class   set   min   html   htm   

<%@page import="java.util.Random"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>class</title>
</head>
<%!public class people//定义一个people类
{
    int height;//身高
    char name;//呢称
    //默认构造函数
    public people(){
        height=(int)(Math.random()*40+160);
        name=(char)(int)(Math.random()*26+a‘);
    }
    //有参构造函数
    public people(int height,char name){
        this.height=height;
        this.name=name;
    }
    //计算标准体重
    public double getWeight(){
        return (this.height-150)*0.6+48;
    }
    //获取身高
    public double getHeight(){
        return this.height;
    }
    //获取呢称
    public char getName(){
        return this.name;
    }
}%>
<body>
<%
//定义两个对象 小红 小明
people xiaoming=new people();
people xiaohong=new people();

//输出小明呢称、身高及标准体重
out.print("xiaoming name:"+xiaoming.getName()+"<br>");
out.print("xiaoming height:"+xiaoming.getHeight()+"cm<br>");
out.print("xiaoming weight:"+xiaoming.getWeight()+"kg<br>");

//输出小红呢称、身高及标准体重
out.print("xiaohong name:"+xiaohong.getName()+"<br>");
out.print("xiaohong height:"+xiaohong.getHeight()+"cm<br>");
out.print("xiaohong weight:"+xiaohong.getWeight()+"kg<br>");
%>
</body>
</html>

 技术图片

 

Class.jsp

标签:函数   tle   默认构造函数   pre   class   set   min   html   htm   

原文地址:https://www.cnblogs.com/sancha/p/10610511.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!