练习1-1

编写并测试一个代表地址的Address类,地址信息由国家 省份 城市 街道 邮编 组成,并可以返回完整的地址信息。

package test1;
class Address{
        private String Country;
        private String Province;
        private String City;
        private String Street;
        private String Zipcode;
        public Address(String Country,String Province,String City,String Street,String Zipcode){
            this.setCountry(Country);           
            this.setProvince(Province);
            this.setCity(City);
            this.setStreet(Street);
            this.setZipcode(Zipcode);    
        }
        public void setCountry(String c){           //设置国家 省份 城市 街道 邮编
                Country=c;
        }
        public void setProvince(String p){
            Province=p;
        }
        public void setCity(String ci){
            City=ci;
        }
        public void setStreet(String s){
            Street=s;
        }
        public void setZipcode(String z){
            Zipcode=z;
        }
        public String getCountry(){          //返回国家 省份 城市 街道 邮编 
            return Country;
        }
        public String getProvince(){
            return Province;
        }
        public String getCity(){
            return City;
        }
        public String getStreet(){
            return Street;
        }
        public String getZipcode(){
            return Zipcode;
        }
        public void print(){
            System.out.println("国家:"+getCountry()+"\n"+"省份:"+getProvince()+"\n"+"城市:"+getCity()
                    +"\n"+"街道:"+getStreet()+"\n"+"邮编:"+getZipcode());
        }
}

public class Test01 {
    public static void main (String args[]){
        
        Address A =new Address("中国", "河南", "林州", "振林街", "111222");
        A.print();
    }

}

 

转载于:https://www.cnblogs.com/ivan999/p/10415847.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值