第四次JAVA作业
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了第四次JAVA作业相关的知识,希望对你有一定的参考价值。
public class TvbDog {
public static void main(String[] args) {
Dog per=new Dog("陈狗","黄色","18个月","藏獒");
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 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作业的主要内容,如果未能解决你的问题,请参考以下文章