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

java第四次作业

时间:2017-03-23 20:22:03      阅读:137      评论:0      收藏:0      [点我收藏+]

标签:pass   ati   system   out   str   颜色   word   题目   home   

题目一:

public class HomeworkDog {

public static void main(String[] args) {
Dog per=new Dog("Luckly","金黄色","三个月","金毛");
per.tell();

}

}
class Dog{
private String Name;
private String Colour;
private String Age;
private String Nature;
public Dog(String Name,String Colour,String Age,String Nature){
this.setName(Name);
this.setColour(Colour);
this.setAge(Age);
this.setNature(Nature);
}
public void tell(){
System.out.println("名字:"+getNature()+",颜色:"+getColour()+",年龄:"+getAge()+",属性:"+getNature());
}
public String getName() {
return Name;
}
public void setName(String name) {
Name = name;
}
public String getColour() {
return Colour;
}
public void setColour(String colour) {
Colour = colour;
}
public String getAge() {
return Age;
}
public void setAge(String age) {
Age = age;
}
public String getNature() {
return Nature;
}
public void setNature(String nature) {
Nature = nature;
}

}

题目二:

public class Work {

public static void main(String[] args) {
User per1=new User("张三","1");
per1.print();
User per2=new User("李四","2");
per2.print();
new User().count();
}

}
class User{
private String Name;
private String Password;
private static int count;
public User(){
count++;
}
public User(String Name,String Password){
this.Name=Name;
this.Password=Password;
count++;
}
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 static int getCount() {
return count;
}
public static void setCount(int count) {
User.count = count;
}
public void print(){
System.out.println("用户名:"+Name+"\t"+"口令密码:"+Password);
}
public void count(){
System.out.println("用户个数:"+(count-1));
}
}

java第四次作业

标签:pass   ati   system   out   str   颜色   word   题目   home   

原文地址:http://www.cnblogs.com/naima/p/6606776.html

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