diff --git "a/work/com/java/minxi/java_20240420/java_2302_\351\203\221\347\245\272\346\265\267_2344310215/Electric.java" "b/work/com/java/minxi/java_20240420/java_2302_\351\203\221\347\245\272\346\265\267_2344310215/Electric.java" new file mode 100644 index 0000000000000000000000000000000000000000..c8546918ca9af1af2ce731cec4cdcf2c777298d0 --- /dev/null +++ "b/work/com/java/minxi/java_20240420/java_2302_\351\203\221\347\245\272\346\265\267_2344310215/Electric.java" @@ -0,0 +1,104 @@ +package com.java.minxi.java_20240420.java_2302_郑祺海_2344310215; + +public class Electric { + //品牌(String)、重量(int)、类别(String)的成员变量; + String brand; + int weight; + String type; + + //洗衣服、做饭、称重的方法; + public void wash() { + System.out.println(brand + type + "正在洗衣服"); + } + + public void cook() { + System.out.println(brand + type + "正在炖鸡汤"); + } + + public void weighting() { + System.out.println(brand + type + "有" + weight + "kg重"); + } + +//无参构造方法; + + public Electric() { + } + + +//有参构造方法 + + public Electric(String brand, int weight, String type) { + this.brand = brand; + this.weight = weight; + this.type = type; + } + +//对品牌、类别进行赋值和取值的实例方法; + public String getBrand() { + return brand; + } + + public void setBrand(String brand) { + this.brand = brand; + } + + public int getWeight() { + return weight; + } + + public void setWeight(int weight) { + this.weight = weight; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + +//品牌(String)、类别(String)的成员变量; + public static class Vrv { +//创建空调静态内部类 + String brand; + String type; + +//制冷、制热的方法; + public void cold() { + System.out.println(brand + type + "正在制冷"); + } + + public void hot() { + System.out.println(brand + 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; + } + +//无参构造方法; + public Vrv() { + } +//有参构造方法; + public Vrv(String brand, String type) { + this.brand = brand; + this.type = type; + } + } + +} diff --git "a/work/com/java/minxi/java_20240420/java_2302_\351\203\221\347\245\272\346\265\267_2344310215/Main.java" "b/work/com/java/minxi/java_20240420/java_2302_\351\203\221\347\245\272\346\265\267_2344310215/Main.java" new file mode 100644 index 0000000000000000000000000000000000000000..6abe39f857ce6a56a241d04750f036116f43e5e1 --- /dev/null +++ "b/work/com/java/minxi/java_20240420/java_2302_\351\203\221\347\245\272\346\265\267_2344310215/Main.java" @@ -0,0 +1,64 @@ +package com.java.minxi.java_20240420.java_2302_郑祺海_2344310215; + +public class Main { + public static void main(String[] args) { + Electric e1 = new Electric(); + e1.brand = "海尔"; + e1.type = "洗衣机"; + e1.wash(); + + Electric e2 = new Electric(); + e2.brand = "美的"; + e2.type = "电饭锅"; + e2.cook(); + + Electric e3 = new Electric(); + e3.brand = "海尔"; + e3.type = "冰箱"; + e3.weight = 50; + e3.weighting(); + + Electric.Vrv e4 = new Electric.Vrv(); + e4.brand = "大金"; + e4.type = "空调"; + e4.cold(); + + System.out.println("-------------------"); + + Electric e5 = new Electric(); + e5.setBrand("海尔"); + e5.setType("洗衣机"); + e5.wash(); + + Electric e6 = new Electric(); + e6.setBrand("美的"); + e6.setType("电饭锅"); + e6.cook(); + + Electric e7 = new Electric(); + e7.setBrand("海尔"); + e7.setType("冰箱"); + e7.setWeight(50); + e7.weighting(); + + Electric.Vrv e8 = new Electric.Vrv(); + e8.setBrand("大金"); + e8.setType("空调"); + e8.cold(); + + System.out.println("-------------------"); + + Electric e9 = new Electric("海尔",0,"洗衣机"); + e9.wash(); + + Electric e10 = new Electric("美的",0,"电饭锅"); + e10.cook(); + + Electric e11 = new Electric("海尔",50,"冰箱"); + e11.weighting(); + + Electric.Vrv e12 = new Electric.Vrv("大金","空调"); + e12.cold(); + + } +}