diff --git "a/work/com/java/minxi/java_20240422/java_2301_\350\224\241\347\216\256\351\223\255_2314320207/Electrical207.java" "b/work/com/java/minxi/java_20240422/java_2301_\350\224\241\347\216\256\351\223\255_2314320207/Electrical207.java" new file mode 100644 index 0000000000000000000000000000000000000000..23dfba41340d4d2c0236913b5fb69ccf7929860c --- /dev/null +++ "b/work/com/java/minxi/java_20240422/java_2301_\350\224\241\347\216\256\351\223\255_2314320207/Electrical207.java" @@ -0,0 +1,140 @@ +package com.java.minxi.java_20240422.java_2301_蔡玮铭_2314320207; + +/** + * 电器类 + */ +public class Electrical207 { + /** + * 成员变量 + */ + String brand; //品牌 + int weight; //重量 + String type; //类别 + + /** + * 成员方法 + */ + //洗衣服 + public String washClothes() { + return "“" + brand + type + "正在洗衣服”"; + } + + //做饭 + public String cook() { + return "“" + brand + type + "正在炖鸡汤”"; + } + + //称重 + public String weighing() { + return "“" + brand + type + "有" + weight + "kg重”"; + } + + /** + * 实例方法 + */ + //品牌赋值 + public void setBrand(String brand) { + this.brand = brand; + } + + //品牌取值 + public String getBrand() { + return brand; + } + + //重量赋值 + public void setWeight(int weight) { + this.weight = weight; + } + + //重量取值 + public int getWeight() { + return weight; + } + + //类别赋值 + public void setType(String type) { + this.type = type; + } + + //类别取值 + public String getType() { + return type; + } + + /** + * 构造方法 + */ + //无参构造方法 + Electrical207() { + + } + + //有参构造方法 + Electrical207(String brand, int weight, String type) { + this.brand = brand; + this.weight = weight; + this.type = type; + } + + /** + * 空调静态内部类 + */ + public static class AirConditioning { + /** + * 内部类成员变量 + */ + String brand; //品牌 + String type; //类别 + + /** + * 内部类成员方法 + */ + //制冷 + public String refrigeration() { + return "“" + brand + type + "正在制冷”"; + } + + //制热 + public String Heating() { + return "“" + brand + type + "正在制热”"; + } + + /** + * 内部类实例方法 + */ + //品牌赋值 + public void setBrand(String brand) { + this.brand = brand; + } + + //品牌取值 + public String getBrand() { + return brand; + } + + //类别赋值 + public void setType(String type) { + this.type = type; + } + + //类别取值 + public String getType() { + return type; + } + + /** + * 内部类构造方法 + */ + //无参构造方法 + AirConditioning() { + + } + + //有参构造方法 + public AirConditioning(String brand, String type) { + this.brand = brand; + this.type = type; + } + } +} diff --git "a/work/com/java/minxi/java_20240422/java_2301_\350\224\241\347\216\256\351\223\255_2314320207/Electrical207Main.java" "b/work/com/java/minxi/java_20240422/java_2301_\350\224\241\347\216\256\351\223\255_2314320207/Electrical207Main.java" new file mode 100644 index 0000000000000000000000000000000000000000..c6657a3985148eb56b29edc58a905eaa4c99533a --- /dev/null +++ "b/work/com/java/minxi/java_20240422/java_2301_\350\224\241\347\216\256\351\223\255_2314320207/Electrical207Main.java" @@ -0,0 +1,61 @@ +package com.java.minxi.java_20240422.java_2301_蔡玮铭_2314320207; + +public class Electrical207Main { + public static void main(String[] args) { + //1)使用简单的对象调用属性方式对属性赋值并在控制台中输出: + Electrical207 e1 = new Electrical207(); + e1.brand = "海尔"; + e1.type = "洗衣机"; + + + Electrical207 e2 = new Electrical207(); + e2.brand = "美的"; + e2.type = "电饭锅"; + + Electrical207 e3 = new Electrical207(); + e3.brand = "海尔"; + e3.weight = 50; + e3.type = "冰箱"; + + Electrical207.AirConditioning e4 = new Electrical207.AirConditioning(); + e4.brand = "大金"; + e4.type = "空调"; + + //输出 + System.out.println(e1.washClothes() + "," + e2.cook() + "," + e3.weighing() + "," + e4.refrigeration() + ";\n"); + + //2)使用实例方法的方式对属性赋值并在控制台中输出: + Electrical207 e11 = new Electrical207(); + e11.setBrand("海尔"); + e11.setType("洗衣机"); + + Electrical207 e22 = new Electrical207(); + e22.setBrand("美的"); + e22.setType("电饭锅"); + + Electrical207 e33 = new Electrical207(); + e33.setBrand("海尔"); + e33.setWeight(50); + e33.setType("冰箱"); + + Electrical207.AirConditioning e44 = new Electrical207.AirConditioning(); + e44.setBrand("大金"); + e44.setType("空调"); + + //输出 + System.out.println(e11.washClothes() + "," + e22.cook() + "," + e33.weighing() + "," + e44.refrigeration() + ";\n"); + + //3)使用构造方法的方式对属性赋值并在控制台中输出: + Electrical207 e111 = new Electrical207("海尔", 0, "洗衣机"); + + Electrical207 e222 = new Electrical207("美的", 0, "电饭锅"); + + Electrical207 e333 = new Electrical207("海尔", 50, "冰箱"); + + Electrical207.AirConditioning e444 = new Electrical207.AirConditioning("大金", "空调"); + + //输出 + System.out.println(e111.washClothes() + "," + e222.cook() + "," + e333.weighing() + "," + e444.refrigeration() + ";"); + + } +}