类的设计2源代码
class Address{ private String nation; private String province; private String city; private String street; private String zipCode; public Address(){ } public Address(String nation,S
class Address{
private String nation;
private String province;
private String city;
private String street;
private String zipCode;
public Address(){
}
public Address(String nation,String zipCode,String province,String city,String street){
this.setNation(nation);
this.setZipCode(zipCode);
this.setProvince(province);
this.setCity(city);
this.setStreet(street);
}
public void setNation(String nation){
this.nation=nation;
}
public void setProvince(String province){
this.province=province;
}
public void setCity(String city){
this.city=city;
}
public void setStreet(String street){
this.street=street;
}
public void setZipCode(String zipCode){
this.zipCode=zipCode;
}
public String getNation(){
return this.nation;
}
public String getZipCode(){
return zipCode;
}
public String getProvince(){
return this.province;
}
public String getCity(){
return this.city;
}
public String getStreet(){
return this.street;
}
public String getInfo(){
return "地址信息:/n"+
"/t国家:"+this.getNation()+"/n"+
"/t邮编:"+this.getZipCode()+"/n"+
"/t省份:"+this.getProvince()+"/n"+
"/t城市:"+this.getCity()+"/n"+
"/t街道:"+this.getStreet()+"/n";
}
}
public class AddressDemo{
public static void main(String[]args){
Address address=new Address("美国","56-24-89","加州","硅谷","唐人街306");
System.out.println(address.getInfo());
}
}
开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!
更多推荐
所有评论(0)