码迷,mamicode.com
首页 > 编程语言 > 详细

3.20 Java

时间:2016-03-20 19:28:28      阅读:185      评论:0      收藏:0      [点我收藏+]

标签:

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.country=country;
this.province=province;
this.city=city;
this.street=street;
this.zipcode=zipcode;
}
public String getCountry()
{
return this.country;
}
public void setCountry(String country)
{
this.country=country;
}
public String getProvince()
{
return province;
}
public void setProvince(String province)
{
this.province=province;
}
public String getCity()
{
return city;
}
public void setCity(String city)
{
this.city=city;
}
public String getStreet()
{
return street;
}
public void setStreet(String street)
{
this.street=street;
}
public String getZipcode()
{
return zipcode;
}
public void setZipcode(String zipcode)
{
this.zipcode=zipcode;
}
public void print()
{
System.out.println("国家:"+this.country+"\n"+"省份:"+this.province+"\n"+"城市:"+this.city+"\n"+"街道:"+this.street+"\n"+"邮编:"+zipcode);
}
}
public class Test01
{
public static void main(String args[])
{
Address add=new Address("中国","北京","北京","牛富路","101301");
add.print();
}
}

技术分享

 

class Employee
{
private String number;
private String name;
private int salary;
private int increase;
public Employee(String number,String name,int salary,int increase)
{
this.number=number;
this.name=name;
this.salary=salary;
this.increase=increase;
}
public String getNumber()
{
return number;
}
public void setNumber(String number)
{
this.number=number;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name=name;
}
public int getSalary()
{
return salary;
}
public void setSalary(int salary)
{
this.salary=salary;
}
public int getIncrease()
{
return increase;
}
public void setIncrease(int increase)
{
this.increase=increase;
}
public int sum()
{
return salary+increase;
}
public void print()
{
System.out.print("员工编号:"+this.number+"\n"+"员工姓名:"+this.name+"\n"+"基本工资:"+this.salary+"\n"+"总工资:"+this.sum());
}
}
public class Test02
{
public static void main(String args[])
{
Employee emp=new Employee("01","小明",6000,290);//
emp.print();
}
}

技术分享

 

class Dog
{
private String name;
private String colour;
private int age;
public Dog(String name,String colour,int age)
{
this.name=name;
this.colour=colour;
this.age=age;
}
public void print()
{
System.out.println("名字:"+this.name+"\n"+"颜色:"+this.colour+"\n"+"年龄:"+this.age);
}
}
class Test03
{
public static void main(String args[])
{
Dog dog=new Dog("大白","黑色",2);
dog.print();
}
}

技术分享

 

class User
{
private String name;
private String password;
private static int count=0;
public User()
{
count++;
}
public User(String name)
{
count++;
this.name=name;
}
public User(String name,String password)
{
count++;
this.name=name;
this.password=password;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name=name;
}
public String getPassword()
{
return password;
}
public void setPassword(String password)
{
this.password=password;
}
public void print()
{
System.out.println("用户个数:"+count);
System.out.println("用户名:"+this.name+"\t"+"密码:"+this.password);
}
}
public class Test04
{
public static void main(String args[])
{
User user1=new User();
user1.print();
User user2=new User("大哥");
user2.print();
User user3=new User("二哥","haha");
user3.print();
}
}

技术分享

3.20 Java

标签:

原文地址:http://www.cnblogs.com/Godxi/p/5299083.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!