Java oop代码5(原创方法):添加非静态的方法,买手机时,设置手机名称

//创建一个Human类
//添加一个非静态属性String mobile(手机),添加非静态的方法:买手机时,设置手机名称
//丟手机时,手机名称设置为null
//添加一个静态属性long count(世界人口总数) =
//1500000000;添加静态方法:出生(人口数+1),死亡(人口数-1)。在main方法中调用。
package a;
import java.util.*;
public class Human {// public可不写,不写就有默认的修饰访问符
private String mobile;// 用private会更安全,但要用上getXXX() setxxx()
private static long count = 1500000000;
public String getMobile() {
return mobile;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
public static long getCount() {
return count;
}
public static void setCount(long count) {
Human.count = count;
}
public void info() { // 定义一个方法
Scanner sstring = new Scanner(System.in);
Scanner sint = new Scanner(System.in);
System.out.println("请输入你的操作:1.买手机 2.丟手机");
int num = sint.nextInt();
if (num == 1) {
System.out.println("请输入手机名称");
String uname = sstring.next();
System.out.println("买手机,手机名称为" + uname);
} else if (num == 2) {
mobile = null;
System.out.println("丟手机时,手机名称设置为:" + mobile);
} else {
System.out.println("输入错误");
}
}
public static void me() {
count = count + 1;
System.out.println("出生(人口数+1):" + count);
count = count - 1;
System.out.println("死亡(人口数-1):" + count);
}
public static void main(String[] args) {
Human a = new Human();
a.info();
Human.me();
}
}