java 程序题求解(完整过程)
编写一个类Message用来表示人们的通信信息,它拥有单独的姓名字段、性别字段、年龄字段、联系电话字段和通信地址字段。为每个字段定义读取和更新该字段信息的方法,并定义一个...
编写一个类Message用来表示人们的通信信息,它拥有单独的姓名字段、性别字段、年龄字段、联系电话字段和通信地址字段。为每个字段定义读取和更新该字段信息的方法,并定义一个toString()方法,以生成格式化的输出各信息字段结果。
展开
2个回答
展开全部
public class Message{
//姓名字段、性别字段、年龄字段、联系电话字段和通信地址字段
private String name;
private String sex;
private int age;
private String phone;
private String address;
public void setName(String name) {
this.name = name;
}
public void setAge(int age) {
this.age = age;
}
public void setPhone(String phone) {
this.phone = phone;
}
public void setAddress(String address) {
this.address = address;
}
public String getName() {
return (this.name);
}
public int getAge() {
return (this.age);
}
public String getPhone() {
return (this.phone);
}
public String getAddress() {
return (this.address);
}
public void setSex(String sex) {
this.sex = sex;
}
public String getSex() {
return (this.sex);
}
//String mane,String sex,int age,String phone,String address
public void getString(Message message)
{
System.out.print("姓名:"+this.getName()+"\n性别:"+this.getSex()+"\n年龄:"+this.getAge()+"\n联系电话:"+this.getPhone()+"\n地址:"+this.getAddress());;
}
}
class Demo{
public static void main(String [] args){
Message message=new Message();
message.setName("张三");
message.setSex("男人");
message.setAge(10);
message.setPhone("1234567890123456789");
message.setAddress("不知道什么大街100号");
message.getString(message);
}
}
这样的?还是其他的什么?
//姓名字段、性别字段、年龄字段、联系电话字段和通信地址字段
private String name;
private String sex;
private int age;
private String phone;
private String address;
public void setName(String name) {
this.name = name;
}
public void setAge(int age) {
this.age = age;
}
public void setPhone(String phone) {
this.phone = phone;
}
public void setAddress(String address) {
this.address = address;
}
public String getName() {
return (this.name);
}
public int getAge() {
return (this.age);
}
public String getPhone() {
return (this.phone);
}
public String getAddress() {
return (this.address);
}
public void setSex(String sex) {
this.sex = sex;
}
public String getSex() {
return (this.sex);
}
//String mane,String sex,int age,String phone,String address
public void getString(Message message)
{
System.out.print("姓名:"+this.getName()+"\n性别:"+this.getSex()+"\n年龄:"+this.getAge()+"\n联系电话:"+this.getPhone()+"\n地址:"+this.getAddress());;
}
}
class Demo{
public static void main(String [] args){
Message message=new Message();
message.setName("张三");
message.setSex("男人");
message.setAge(10);
message.setPhone("1234567890123456789");
message.setAddress("不知道什么大街100号");
message.getString(message);
}
}
这样的?还是其他的什么?
展开全部
public Class Message{
private String name;
private String sex;
private int age;
private String tel;
private String address
getter/setter 自动生成
public String toString(){
return "姓名"+name+“\n性别”+sex+“\n年龄”+age+"\n 电话"+tel+“\n地址”+address;
}
}
private String name;
private String sex;
private int age;
private String tel;
private String address
getter/setter 自动生成
public String toString(){
return "姓名"+name+“\n性别”+sex+“\n年龄”+age+"\n 电话"+tel+“\n地址”+address;
}
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |