作业不会做!

moxi225 2004-04-06 08:45:44
1.1 定义一个名为Human的类,来描述人的一些特性,具体如下:(变量和方法是定义为对象成员还是类成员?请认真思考)
1.1.1 定义一个私有的字符串类型的变量strName来存储人的名字(该定义为对象变量还是类变量自己思考,下同)
1.1.2 定义一个私有的字符串类型的变量strID来存储身份证号码
1.1.3 定义一个私有的字符串类型的变量strSex来存储性别
1.1.4 定义一个私有的浮点数值类型的变量fHeight来存储身高

1.1.5 定义两个构造方法(函数),一个不带参数,利用一些缺省的值来设置变量的值,例如将strName设置为"中国人";
另一个含四个参数String strName,String strID,String strSex,float fHeight分别用来设置类中名字、省份证号码、性别、身高的值
1.1.6 定义公有类型的方法setName与getName分别用来设置和返回姓名
1.1.7 定义公有类型的方法setID与getID分别用来设置和返回身份证号码
1.1.8 定义公有类型的方法setSex与getSex分别用来设置和返回性别
1.1.9 定义公有类型的方法setHeight与getHeight分别用来设置和返回人的身高
1.1.10 定义一个公有类型的方法printTitle()用来输出标题"姓名 生份证号码 性别 身高"
1.1.11 定义一个公有类型的方法printInfo()用来输出人的姓名、生份证号码、性别、身高,要求与标题对齐
...全文
89 18 打赏 收藏 转发到动态 举报
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
wzrlover 2004-04-06
  • 打赏
  • 举报
回复
faint~~看书去吧
fkys 2004-04-06
  • 打赏
  • 举报
回复
不自己练怎能有收获?
建议楼主参考各位回复人的帖子,还是自己实战一下。
wilddonkey 2004-04-06
  • 打赏
  • 举报
回复
up
cxb1004 2004-04-06
  • 打赏
  • 举报
回复
呵呵 这才是比较完善的一个类文件,你试一下,再不行,多给点分,我给你写一个;
suntao222 2004-04-06
  • 打赏
  • 举报
回复
class Human
{
private String strName;
private String strID;
private String strSex;
private float fHeight;

public Human()
{
this.strName = "中国人";
this.strID = "12345";
this.strSex = "男";
this.fHeight = 180;
}

public Human(String strName, String strID, String strSex, float fHeight)
{
this.strName = strName;
this.strID = strID;
this.strSex = strSex;
this.fHeight = fHeight;
}

public void setName(String strName)
{
this.strName = strName;
}

public String getName(String strName)
{
return this.strName;
}

public void setID(String strID)
{
this.strID = strID;
}

public String getID(String strID)
{
return this.strID;
}

public void setSex(String strSex)
{
this.strSex = strSex;
}

public String getSex(String strSex)
{
return this.strSex;
}

public void setHeight(float fHeight)
{
this.fHeight = fHeight;
}

public float getHeight(float fHeight)
{
return this.fHeight;
}

public void printTitle()
{
System.out.println("姓名 身份证号码 性别 身高");
}

public void printInfo()
{
System.out.println(this.strName+" "+this.strID+" "+this.strSex+" "+this.fHeight);
}
}

class a1
{
public static void main(String [] args)
{
Human a = new Human();

a.printTitle();
a.printInfo();
}
}
meiyuntao 2004-04-06
  • 打赏
  • 举报
回复
你们老师既然给出了,应该也学了点基础了,自己慢慢摸索去写啦,这样让别人替你写,还是学不到什么的,自己去把课本翻翻~
moxi225 2004-04-06
  • 打赏
  • 举报
回复
我才刚刚入门啊,不知道行情哦!
wwj0213 2004-04-06
  • 打赏
  • 举报
回复
这么简单你自己慢慢写吧!还只出15分,鬼才去写
OnlyLikeJava 2004-04-06
  • 打赏
  • 举报
回复
public static void main(String args[]){
}
moxi225 2004-04-06
  • 打赏
  • 举报
回复
鬼才的不行啊!
没有main函数
programer23 2004-04-06
  • 打赏
  • 举报
回复
qukmei(鬼才)的 你试试 。
不满意,在来问。
qukmei 2004-04-06
  • 打赏
  • 举报
回复
public class Human()
{
private String strName;
private String strID;
private String strSex;
private float fHeight;

public void Human()
{
strName="李世民";
strID="001";
strSex="男";
fHeight=1.80;
}
public void Human(String tmpName,String tmpId,String tmpSex,float tmpHeight)
{
strName=tmpName;
strID=tmpId;
strSex=tmpSex;
fHeight=tmpHeight;
}

public void setName(String tmpName){ strName=tmpName;}
public void setID(String tmpID){ strID=tmpID;}
public void setSex(String tmpSex){ strSex=tmpSex;}
public void setHeight(String tmpHeight){ fHeight=tmpHeight;}

public String getName() { return strName;}
public String getID() { return strID;}
public String getSex() { return strSex;}
public String getHeight() { return fHeight;}

public void printTitle()
{
System.out.println(strName+"_"+strID+"_"+strSex+"_"+fHeight);
}

public void printInfo()
{
类似printTitle();
}

}
yeshucheng 2004-04-06
  • 打赏
  • 举报
回复
你们老师出的这个题目还确实不错的
casemy 2004-04-06
  • 打赏
  • 举报
回复
这个很容易的,简单看一下书就可以了
weichenggao 2004-04-06
  • 打赏
  • 举报
回复
不难的吧,自己写哦!
caoze 2004-04-06
  • 打赏
  • 举报
回复
把面向对象的实现部分看一下就OK喽

估计不会有人替你写出来
Leemaasn 2004-04-06
  • 打赏
  • 举报
回复
慢慢做。
cxb1004 2004-04-06
  • 打赏
  • 举报
回复

/*
* Created on 2004-4-6
* 直接把我的代码考上去就可以了,不过最好还是要看懂,给分啊!
*@author cxb
*@version 1.0
*/
package classes;

/**
* 1.1
*/
public class Human {
/*
* 1.1.1
*/
private String strName;
/*
* 1.1.2
*/
private String strID;
/*
* 1.1.3
*/
private String strSex;
/*
* 1.1.4
*/
private float fHeight;


/*
* 1.1.5
*/
Human(){
this.strName="中国人";
this.strID="000000000000000";
this.strSex="男";
this.fHeight=0.0f;
}

Human(String strName,String strID,String strSex,float fHeight){
this.strName=strName;
this.strID=strID;
this.strSex=strSex;
this.fHeight=fHeight;
}

/*
* 1.1.6
*/
public void setName(String str){
this.strName=str;
}

public String getName(){
return this.strName;
}

/*
* 1.1.7
*/
public void setID(String str){
this.strID=str;
}

public String getID(){
return this.strID;
}

/*
* 1.1.8
*/
public void setSex(String str){
this.strSex=str;
}

public String getSex(){
return this.strSex;
}

/*
* 1.1.9
*/
public void setHeight(String str){
this.fHeight=Float.parseFloat(str);
}

public float getHeight(){
return this.fHeight;
}

/*
* 1.1.10
*/
public void printTitle(){
System.out.println("姓名"+this.strName+";身份证号码"+this.strID+";性别"+this.strSex+";身高"+this.fHeight+";");

}

/*
* 1.1.11
*/
public void printInfo(){
System.out.println("输入人的信息——");
System.out.println("姓名:"+this.strName);
System.out.println("身份证号码:"+this.strID);
System.out.println("性别:"+this.strSex);
System.out.println("身高:"+this.fHeight);
System.out.println("");
}


public static void main(String[] args) {
Human h=new Human();
h .printTitle();
//h.printInfo();
}


}

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧