其他分享
首页 > 其他分享> > 【保存】

【保存】

作者:互联网

点击查看代码
package chap05;

public class Contract {
	private String name;
	private String gender;
	private String email;
	private String[] phones;

	public String getGender() {
		return gender;
	}

	public void setGender(String gender) {
		this.gender = gender;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String[] getPhones() {
		return phones;
	}

	public void setPhones(String[] phones) {
		this.phones = phones;
	}

	public String getName() {
		return name;
	}

	public Contract() {
	}

	public Contract(String name, String gender, String email, String[] phones) {
		setName(name);
		setGender(gender);
		setEmail(email);
		setPhones(phones);
	}

	public Contract(String name, String[] phones) {
		this(name, "", "", phones);
	}

	//姓名不能为空
	public void setName(String name) {
		if (name == null || name.equals(""))
			return;
		this.name = name;
	}

	public void display() {
		System.out.println("姓名:" + getName() + "\t性别:" + getGender() + "\te-mail:" + getEmail());
		System.out.print("联系电话:\t");
		for (int i = 0; i < phones.length; i++) {
			System.out.print(phones[i] + "\t");
		}
		System.out.println();
	}

	public static void main(String[] args) {
		Contract c = new Contract("王新明", new String[] { "13602344578", "13506334789", "010-34567913" });
		c.display();
	}
}

点击查看代码
package chap05;

import java.text.SimpleDateFormat;
import java.util.Date;

public class Family extends Contract {
	
	private Date birthday;
	private String address;
	
	
	public Family(String name, String gender, String email, String[] phones, Date birthday, String address) {
		super(name, gender, email, phones);//调用父类的构造方法 必须是第一句话
		setBirthday(birthday);
		setAddress(address); 
	}
	public Family() {
		
	}
	public Family(String name, String[] phones) {
		super(name,phones);
			
		}
	public Date getBirthday() {
		return birthday;
	}
	public void setBirthday(Date birthday) {
		this.birthday = birthday;
	}
	public String getAddress() {
		return address;
	}
	public void setAddress(String address) {
		this.address = address;
	}
	public void dispaly() {
		super.display();//调用父类被重写的方法
		 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		System.out.println("生日"+this.getBirthday()+"\t地址"+this.getAddress());
	}
	
	

}

点击查看代码
package chap05;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class ContractTest {

	public static void main(String[] args) throws ParseException {
		Contract c = new Contract("王新明", new String[] { "13602344578", "13506334789", "010-34567913" });
		c.display();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		Date birthday = sdf.parse("2001-09-12");	
		
		Family f = new Family("王虎", "男","wh@163.com",new String[] { "13602341234", "13506332356", "010-34564568" },birthday,"山东烟台");
		f.display();
//		Partner p = new Partner("张一鸣", "男","zym@163.com",new String[] { "13600041234", "13501232356" }, 
//				"工程师", new Company("千度烟台", "烟台莱山区", "0535-6023458", "0535-6026457"));
//		p.display();
	}

}

标签:name,phones,void,保存,new,public,String
来源: https://www.cnblogs.com/zhujiaozhu/p/15355346.html