homework for Java

public class Dog {
private String name;
private String color;
private int age;
public Dog(String name, String color, int age) {
this.name = name;
this.color = color;
this.age = age;
}
public void print() {
System.out.print("名字: " + this.name + "\n" + "颜色:" + this.color + "\n"
+ "年龄:" + this.age);
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
public class User {
private String name;
private String password;
private static int num;
public User() {
num++;
}
public User(String name) {
this.name = name;
num++;
}
public User(String name, String password) {
this.name = name;
this.password = password;
num++;
}
public void print() {
System.out.print("用户个数:" + num + "\n");
System.out.println("名字: " + name + "\t" + "口令:" + password + "\n");
}
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;
}
}

 

posted @ 2017-03-23 12:42  bgd160809202  阅读(164)  评论(0编辑  收藏  举报