diff --git "a/work/com/java/minxi/java_20240422/java_2301_\345\217\266\345\212\237\347\205\247_2344310115/Current.java" "b/work/com/java/minxi/java_20240422/java_2301_\345\217\266\345\212\237\347\205\247_2344310115/Current.java" new file mode 100644 index 0000000000000000000000000000000000000000..d682d848dcfeac014a7225c5da78da28c7adb455 --- /dev/null +++ "b/work/com/java/minxi/java_20240422/java_2301_\345\217\266\345\212\237\347\205\247_2344310115/Current.java" @@ -0,0 +1,124 @@ +package com.java.minxi.java_20240422.java_2301_叶功照_2344310115; + +public class Current { + String brand; + + int weight; + + String type; + + /** + * 无构造方法 + **/ + //洗衣服的方法 + public void washing() { + System.out.println(brand + type + "正在洗衣服"); + } + + //做饭的方法 + public void cooking() { + System.out.println(brand + type + "正在炖鸡汤"); + } + + //称量的方法 + public void weighting() { + System.out.println(brand + type + "有" + weight + "kg重"); + } + + /** + * 实例方法 + */ + 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; + } + + public void setWeight(int weight) { + this.weight = weight; + } + + public int getWeight() { + return weight; + } + + /** + * 有参方法 + */ + Current(String brand, String type, int weight) { + this.brand = brand; + this.type = type; + this.weight = weight; + } + + /** + * 无参方法 + */ + Current() { + + } + + /** + * 创建空调类 + */ + public static class Airconditioner { + String brand; + + String type; + + //无参方法 + Airconditioner() { + } + + //有参方法 + Airconditioner(String brand, String type) { + this.brand = brand; + this.type = type; + } + + /** + * 制冷制热方法 + */ + public void makecold() { + System.out.println(brand + type + "正在制冷"); + } + + public void makehot() { + System.out.println(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; + } + + } + + + +} + diff --git "a/work/com/java/minxi/java_20240422/java_2301_\345\217\266\345\212\237\347\205\247_2344310115/Main.java" "b/work/com/java/minxi/java_20240422/java_2301_\345\217\266\345\212\237\347\205\247_2344310115/Main.java" new file mode 100644 index 0000000000000000000000000000000000000000..0d8ecc9f337ab4bf77f1aeab3ca820551eeec066 --- /dev/null +++ "b/work/com/java/minxi/java_20240422/java_2301_\345\217\266\345\212\237\347\205\247_2344310115/Main.java" @@ -0,0 +1,66 @@ +package com.java.minxi.java_20240422.java_2301_叶功照_2344310115; + +public class Main { + public static void main(String[] args) { + //简单方法 + Current cr_01 = new Current(); + cr_01.brand = "海尔"; + cr_01.type = "洗衣机"; + cr_01.washing(); + + Current cr_02 = new Current(); + cr_02.brand = "美的"; + cr_02.type = "电饭煲"; + cr_02.cooking(); + + Current cr_03 = new Current(); + cr_03.brand = "海尔"; + cr_03.type = "冰箱"; + cr_03.weight = 50; + cr_03.weighting(); + + Current.Airconditioner airconditioner = new Current.Airconditioner(); + airconditioner.brand = "太金"; + airconditioner.type = "空调"; + airconditioner.makecold(); + + System.out.println(); + //实例方法 + Current ar_01 = new Current(); + ar_01.setBrand("海尔"); + ar_01.setType("洗衣机"); + ar_01.washing(); + + Current ar_02 = new Current(); + ar_02.setBrand("美的"); + ar_02.setType("电饭煲"); + ar_02.cooking(); + + Current ar_03 = new Current(); + ar_03.setBrand("海尔"); + ar_03.setType("冰箱"); + ar_03.setWeight(50); + ar_03.weighting(); + + Current.Airconditioner ar_04=new Current.Airconditioner(); + ar_04.setBrand("太金"); + ar_04.setType("空调"); + ar_04.makecold(); + + + System.out.println(); + + //构造方法 + Current a1 = new Current("海尔", "洗衣机", 0); + a1.washing(); + + Current a2 = new Current("美的", "电饭煲", 0); + a2.cooking(); + + Current a3 = new Current("海尔", "冰箱", 50); + a3.weighting(); + + Current.Airconditioner a4 = new Current.Airconditioner("太金", "空调"); + a4.makecold(); + } +}