Cats.java
import lombok.Getter; import lombok.Setter; @Getter @Setter public class Cats { /**静态变量 * 使用public 可以在Application中更改 * 使用private,同时设置Getter() */ private static String claim = "天方夜谭"; public static String getClaim(){ return claim; } /** 该类中包含4个变量,并对变量进行封装,包括: * @param 名字 * @param 年龄 * @param 种类 * @param 食物 */ private String name; private int age; private String variety; private String food; /** * 传递Structure()方法 */ public Cats(){ } public Cats(String name, int age, String variety, String food) { this.name = name; this.age = age; this.variety = variety; this.food = food; } /** * 传递Getter()和Setter()方法 * @return 一个int类型参数 */ public int getAge() { return age; } public void setAge(int age) { if (age < 0 || age > 30) { System.out.println("该年龄输入有误,请重新输入;"); } else { this.age = age; } } /** * 传递to String()方法 */ @Override public String toString() { return "Cats{" + "name='" + name + '\'' + ", age=" + age + ", variety='" + variety + '\'' + ", food='" + food + '\'' + '}'; } /**该类中有3种行为,包括: * @吃饭; * @睡觉: * @发狂: */ public void eat(){ System.out.println("正在吃饭"); } public void sleep(){ System.out.println("正在睡觉"); } public void crazy(){ System.out.println("正在发狂"); } //静态方法 public static void help(){ System.out.println("救助"); } } Plot.java
public class plot { /**使用单例设计模式 * 定义对象的名称:富贵小区 * 对小区设置为不可更改 */ private static plot plotInstance = new plot(); //定义plot为不可更改 private plot(){ } public static plot getPlotInstance(){ return plotInstance; } public void plotName(){ System.out.println("富贵小区"); } }
ApplicaionRun.java
import java.util.concurrent.Callable; public class ApplicationRun { /**用户注册信息,包括: * @姓名 * @年龄 * @种类 * @食物 */ public static void main(String[] args) { plot uniquePlot = plot.getPlotInstance(); uniquePlot.plotName(); Cats XIAO_MING_FAMILY_PETS = new Cats("Tom", 2, "布偶", "猫粮和小鱼干"); Cats XIAO_ZHANG_FAMILY_PETS = new Cats("MIMI", 3, "狸花猫", "老鼠和小鸟"); System.out.println("XIAO_MING_FAMILY_PETS = " + XIAO_MING_FAMILY_PETS); System.out.println("XIAO_ZHANG_FAMILY_PETS = " + XIAO_ZHANG_FAMILY_PETS); /**显示用户行为信息,包括: * @吃饭 * @睡觉 * @发狂 */ XIAO_MING_FAMILY_PETS.crazy(); XIAO_ZHANG_FAMILY_PETS.eat(); Cats.help(); System.out.println(" Cats.getClaim = " + Cats.getClaim()); } }