diff --git "a/work/com/java/minxi/java_20240420/java_2302_\346\210\264\345\244\251\346\210\220_2344310214/ElectricalAppliance.java" "b/work/com/java/minxi/java_20240420/java_2302_\346\210\264\345\244\251\346\210\220_2344310214/ElectricalAppliance.java" new file mode 100644 index 0000000000000000000000000000000000000000..b2b52027266f7e060463e647062b6278ccd1e359 --- /dev/null +++ "b/work/com/java/minxi/java_20240420/java_2302_\346\210\264\345\244\251\346\210\220_2344310214/ElectricalAppliance.java" @@ -0,0 +1,118 @@ +package com.java.minxi.java_20240420.java_2302_戴天成_2344310214; + +// 创建电器类 +public class ElectricalAppliance { + + // 品牌成员变量 + String brand; + + // 重量成员变量 + int weight; + + // 类别成员变量 + String type; + + // 创建洗衣服方法 + public void WashClothes() { + System.out.println(brand + type + "正在洗衣服"); + } + + // 创建做饭方法 + public void Cook() { + System.out.println(brand + type + "正在炖鸡汤"); + } + + // 创建称重方法 + public void Weighing() { + System.out.println(brand + type + "有" + weight + "kg重"); + } + + // 无参构造器 + public ElectricalAppliance() { + } + + // 有参构造器 + public ElectricalAppliance(String brand, int weight, String type) { + this.brand = brand; + this.weight = weight; + this.type = type; + } + + // 对品牌、重量、类别进行赋值和取值的实例方法 + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public int getWeight() { + return weight; + } + + public void setWeight(int weight) { + this.weight = weight; + } + + public String getBrand() { + return brand; + } + + public void setBrand(String brand) { + this.brand = brand; + } + + + + // 创建空调静态内部类 + public static class AirConditioner { + + // 品牌成员变量 + String brand; + + // 类别成员变量 + String type; + + // 创建制冷方法 + public void Refrigeration() { + System.out.println(brand + type + "正在制冷"); + } + + // 创建制热方法 + public void Heating() { + System.out.println(brand + type + "正在制热"); + } + + // 无参构造器 + public AirConditioner() { + } + + // 有参构造器 + public AirConditioner(String brand, String type) { + this.brand = brand; + this.type = type; + } + + // 对品牌、类别进行赋值和取值的实例方法 + + public String getBrand() { + return brand; + } + + public void setBrand(String brand) { + this.brand = brand; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + } +} + + diff --git "a/work/com/java/minxi/java_20240420/java_2302_\346\210\264\345\244\251\346\210\220_2344310214/Main.java" "b/work/com/java/minxi/java_20240420/java_2302_\346\210\264\345\244\251\346\210\220_2344310214/Main.java" new file mode 100644 index 0000000000000000000000000000000000000000..9278368b12383c321089d3863ae9cd63834e5a37 --- /dev/null +++ "b/work/com/java/minxi/java_20240420/java_2302_\346\210\264\345\244\251\346\210\220_2344310214/Main.java" @@ -0,0 +1,68 @@ +package com.java.minxi.java_20240420.java_2302_戴天成_2344310214; + +public class Main { + public static void main(String[] args) { + + // 1)使用简单的对象调用属性方式对属性赋值并在控制台中输出: + + ElectricalAppliance ea1 = new ElectricalAppliance(); + ea1.brand = "海尔"; + ea1.type = "洗衣机"; + ea1.WashClothes(); + + ElectricalAppliance ea2 = new ElectricalAppliance(); + ea2.brand = "美的"; + ea2.type = "电饭锅"; + ea2.Cook(); + + ElectricalAppliance ea3 = new ElectricalAppliance(); + ea3.brand = "海尔"; + ea3.type = "冰箱"; + ea3.weight = 50; + ea3.Weighing(); + + ElectricalAppliance.AirConditioner ea4 = new ElectricalAppliance.AirConditioner(); + ea4.brand = "大金"; + ea4.type = "空调"; + ea4.Refrigeration(); + + System.out.println("----------------------------"); + + // 2)使用实例方法的方式对属性赋值并在控制台中输出: + ElectricalAppliance ea5 = new ElectricalAppliance(); + ea5.setBrand("海尔"); + ea5.setType("洗衣机"); + ea5.WashClothes(); + + ElectricalAppliance ea6 = new ElectricalAppliance(); + ea6.setBrand("美的"); + ea6.setType("电饭锅"); + ea6.Cook(); + + ElectricalAppliance ea7 = new ElectricalAppliance(); + ea7.setBrand("海尔"); + ea7.setType("冰箱"); + ea7.setWeight(50); + ea7.Weighing(); + + ElectricalAppliance.AirConditioner ea8 = new ElectricalAppliance.AirConditioner(); + ea8.setBrand("大金"); + ea8.setType("空调"); + ea8.Refrigeration(); + + System.out.println("----------------------------"); + + // 3)使用构造方法的方式对属性赋值并在控制台中输出: + ElectricalAppliance ea9 = new ElectricalAppliance("海尔", 0, "洗衣机"); + ea9.WashClothes(); + + ElectricalAppliance ea10 = new ElectricalAppliance("美的", 0, "电饭锅"); + ea10.Cook(); + + ElectricalAppliance ea11 = new ElectricalAppliance("海尔", 50, "冰箱"); + ea11.Weighing(); + + ElectricalAppliance.AirConditioner ea12 = new ElectricalAppliance.AirConditioner("大金", "空调"); + ea12.Refrigeration(); + } +}