18 changed files with 144 additions and 0 deletions
@ -0,0 +1,10 @@ |
|||
# 默认忽略的文件 |
|||
/shelf/ |
|||
/workspace.xml |
|||
# 已忽略包含查询文件的默认文件夹 |
|||
/queries/ |
|||
# Datasource local storage ignored files |
|||
/dataSources/ |
|||
/dataSources.local.xml |
|||
# 基于编辑器的 HTTP 客户端请求 |
|||
/httpRequests/ |
|||
@ -0,0 +1,10 @@ |
|||
<component name="libraryTable"> |
|||
<library name="lib"> |
|||
<CLASSES> |
|||
<root url="jar://$PROJECT_DIR$/jdk-21.0.10/lib/jrt-fs.jar!/" /> |
|||
<root url="jar://$PROJECT_DIR$/jdk-21.0.10/lib/src.zip!/" /> |
|||
</CLASSES> |
|||
<JAVADOC /> |
|||
<SOURCES /> |
|||
</library> |
|||
</component> |
|||
@ -0,0 +1,6 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<project version="4"> |
|||
<component name="ProjectRootManager" version="2" languageLevel="JDK_24" default="true" project-jdk-name="temurin-24" project-jdk-type="JavaSDK"> |
|||
<output url="file://$PROJECT_DIR$/out" /> |
|||
</component> |
|||
</project> |
|||
@ -0,0 +1,8 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<project version="4"> |
|||
<component name="ProjectModuleManager"> |
|||
<modules> |
|||
<module fileurl="file://$PROJECT_DIR$/Desktop.iml" filepath="$PROJECT_DIR$/Desktop.iml" /> |
|||
</modules> |
|||
</component> |
|||
</project> |
|||
@ -0,0 +1,6 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<project version="4"> |
|||
<component name="VcsDirectoryMappings"> |
|||
<mapping directory="" vcs="Git" /> |
|||
</component> |
|||
</project> |
|||
@ -0,0 +1,16 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<module type="JAVA_MODULE" version="4"> |
|||
<component name="NewModuleRootManager" inherit-compiler-output="true"> |
|||
<exclude-output /> |
|||
<content url="file://$MODULE_DIR$"> |
|||
<sourceFolder url="file://$MODULE_DIR$/W1-何欣蓉-202506050223" isTestSource="false" /> |
|||
<sourceFolder url="file://$MODULE_DIR$/w1" isTestSource="false" /> |
|||
<sourceFolder url="file://$MODULE_DIR$/w2" isTestSource="false" /> |
|||
<sourceFolder url="file://$MODULE_DIR$/w4" isTestSource="false" /> |
|||
<sourceFolder url="file://$MODULE_DIR$/w5" isTestSource="false" /> |
|||
<sourceFolder url="file://$MODULE_DIR$/w7" isTestSource="false" /> |
|||
</content> |
|||
<orderEntry type="inheritedJdk" /> |
|||
<orderEntry type="sourceFolder" forTests="false" /> |
|||
</component> |
|||
</module> |
|||
|
After Width: | Height: | Size: 62 KiB |
@ -0,0 +1 @@ |
|||
AI为我协助完成了Python到Java的代码转换,解释了Java中Scanner类的使用方法。当编译出现"找不到符号"错误时,AI指导添加了import语句解决了问题。AI还提供了命令行参数解析和批量文件处理的实现方案,并帮助编写了README文档和运行说明。 |
|||
|
After Width: | Height: | Size: 192 KiB |
@ -0,0 +1,8 @@ |
|||
# 温度转换器 (TemperatureConverter) |
|||
|
|||
这是一个Java版本的温度转换程序,支持摄氏度(°C)与华氏度(°F)之间的相互转换。 |
|||
|
|||
## 编译方法 |
|||
|
|||
```bash |
|||
javac TemperatureConverter.java |
|||
|
After Width: | Height: | Size: 45 KiB |
Binary file not shown.
Binary file not shown.
@ -0,0 +1,79 @@ |
|||
//定义抽象类 Animal
|
|||
abstract class Animal { |
|||
// 抽象方法:没有方法体,子类必须实现
|
|||
public abstract void makeSound(); |
|||
} |
|||
|
|||
//定义接口 Swimmable
|
|||
interface Swimmable { |
|||
// 接口中的方法默认是 public abstract
|
|||
void swim(); |
|||
} |
|||
|
|||
// Dog 类继承 Animal,并实现 Swimmable
|
|||
class Dog extends Animal implements Swimmable { |
|||
// 实现抽象方法 makeSound()
|
|||
@Override |
|||
public void makeSound() { |
|||
System.out.println("汪汪汪!"); |
|||
} |
|||
|
|||
// 实现接口中的 swim() 方法
|
|||
@Override |
|||
public void swim() { |
|||
System.out.println("狗会游泳,正在狗刨..."); |
|||
} |
|||
} |
|||
|
|||
// Cat 类只继承 Animal,不实现 Swimmable
|
|||
class Cat extends Animal { |
|||
// 实现抽象方法 makeSound()
|
|||
@Override |
|||
public void makeSound() { |
|||
System.out.println("喵喵喵~"); |
|||
} |
|||
} |
|||
|
|||
// 主类(测试类)
|
|||
public class AnimalTest { |
|||
public static void main(String[] args) { |
|||
System.out.println("=== 动物叫声系统 ===\n"); |
|||
|
|||
// 多态:父类引用指向子类对象
|
|||
Animal animal1 = new Dog(); |
|||
Animal animal2 = new Cat(); |
|||
|
|||
// 调用 makeSound() - 表现出不同的行为
|
|||
System.out.println("狗的声音:"); |
|||
animal1.makeSound(); // 输出:汪汪汪!
|
|||
|
|||
System.out.println("\n猫的声音:"); |
|||
animal2.makeSound(); // 输出:喵喵喵~
|
|||
|
|||
// 测试游泳能力(需要向下转型)
|
|||
System.out.println("\n=== 游泳测试 ==="); |
|||
|
|||
// Dog 实现了 Swimmable,可以游泳
|
|||
if (animal1 instanceof Swimmable) { |
|||
Swimmable swimmer = (Swimmable) animal1; // 向下转型
|
|||
swimmer.swim(); // 输出:狗会游泳,正在狗刨...
|
|||
} |
|||
|
|||
// Cat 没有实现 Swimmable,不能游泳
|
|||
if (animal2 instanceof Swimmable) { |
|||
System.out.println("猫会游泳"); // 不会执行
|
|||
} else { |
|||
System.out.println("猫不会游泳"); // 输出:猫不会游泳
|
|||
} |
|||
|
|||
// 演示直接使用子类引用
|
|||
System.out.println("\n=== 直接调用 ==="); |
|||
Dog dog = new Dog(); |
|||
dog.makeSound(); // 汪汪汪!
|
|||
dog.swim(); // 狗会游泳,正在狗刨...
|
|||
|
|||
Cat cat = new Cat(); |
|||
cat.makeSound(); // 喵喵喵~
|
|||
// cat.swim(); // 编译错误!Cat没有swim方法
|
|||
} |
|||
} |
|||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in new issue