类名: Contact
属性:
姓名(name)
出生日期(age)
性别(gender)
电话号码(tel)
家庭住址(address)
方法:
写一个show方法(在方法中打印出联系人的每个属性)。
写出测试程序(在主函数中创建若干联系人对象,并为每个属性赋值调用show方法,打印联系人的各个属性信息)
类名: Contact
属性:
姓名(name)
出生日期(age)
性别(gender)
电话号码(tel)
家庭住址(address)
方法:
写一个show方法(在方法中打印出联系人的每个属性)。
写出测试程序(在主函数中创建若干联系人对象,并为每个属性赋值调用show方法,打印联系人的各个属性信息)
public class Contact {
private String name;
private int age;
private String gender;
private String tel;
private String address;
public Contact(String name, int age, String gender, String tel, String address) {
this.name = name;
this.age = age;
this.gender = gender;
this.tel = tel;
this.address = address;
}
public void show() {
System.out.println("Name: " + name);
System.out.println("Age: " + age);
System.out.println("Gender: " + gender);
System.out.println("Tel: " + tel);
System.out.println("Address: " + address);
}
public static void main(String[] args) {
Contact contact1 = new Contact("张三", 25, "男", "1234567890", "北京市朝阳区");
Contact contact2 = new Contact("李四", 30, "女", "0987654321", "上海市浦东新区");
Contact contact3 = new Contact("王五", 28, "男", "1112223333", "广州市天河区");
Contact contact4 = new Contact("赵六", 35, "女", "2223334444", "深圳市福田区");
contact1.show();
contact2.show();
contact3.show();
contact4.show();
}
}