From 9db82eb8453586d83953513565ef8f7c622e9dbc Mon Sep 17 00:00:00 2001 From: ZhangJinxuan <2194936226@qq.com> Date: Tue, 31 Mar 2026 10:29:57 +0800 Subject: [PATCH 1/9] Add ShapeDemo.java in w5 folder --- 6/w5/ShapeDemo.java | 51 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 6/w5/ShapeDemo.java diff --git a/6/w5/ShapeDemo.java b/6/w5/ShapeDemo.java new file mode 100644 index 0000000..998237d --- /dev/null +++ b/6/w5/ShapeDemo.java @@ -0,0 +1,51 @@ +public class ShapeDemo { + public static void main(String[] args) { + // 创建不同形状的对象 + Shape circle = new Circle(); + Shape rectangle = new Rectangle(); + + // 测试drawShape方法 + drawShape(circle); + drawShape(rectangle); + } + + /** + * 调用形状的draw方法 + * @param s 形状对象 + */ + public static void drawShape(Shape s) { + s.draw(); + } +} + +/** + * 形状基类 + */ +class Shape { + /** + * 绘制方法 + */ + public void draw() { + System.out.println("绘制形状"); + } +} + +/** + * 圆形类 + */ +class Circle extends Shape { + @Override + public void draw() { + System.out.println("绘制圆形"); + } +} + +/** + * 矩形类 + */ +class Rectangle extends Shape { + @Override + public void draw() { + System.out.println("绘制矩形"); + } +} \ No newline at end of file From 236d7ae1260f9d6980b3d389c1771a9038f50c53 Mon Sep 17 00:00:00 2001 From: ZhangJinxuan <2194936226@qq.com> Date: Sun, 19 Apr 2026 19:22:15 +0800 Subject: [PATCH 2/9] =?UTF-8?q?=E4=B8=8A=E4=BC=A0w6=E9=87=8C=E7=9A=84?= =?UTF-8?q?=E6=89=80=E6=9C=89Java=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 动物叫声系统.java | 31 +++++++++++++++++++++++++++++++ 测试.java | 23 +++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 动物叫声系统.java create mode 100644 测试.java diff --git a/动物叫声系统.java b/动物叫声系统.java new file mode 100644 index 0000000..563e4ee --- /dev/null +++ b/动物叫声系统.java @@ -0,0 +1,31 @@ +abstract class Animal { + // 抽象方法:动物叫声 + public abstract void makeSound(); +} + +// 2. Swimmable 接口 +interface Swimmable { + // 游泳方法 + void swim(); +} + +// 3. Dog 类:继承 Animal,实现 Swimmable +class Dog extends Animal implements Swimmable { + @Override + public void makeSound() { + System.out.println("小狗汪汪叫:汪汪汪!"); + } + + @Override + public void swim() { + System.out.println("小狗在水里狗刨式游泳!"); + } +} + +// 4. Cat 类:继承 Animal,不实现 Swimmable +class Cat extends Animal { + @Override + public void makeSound() { + System.out.println("小猫喵喵叫:喵喵喵!"); + } +} \ No newline at end of file diff --git a/测试.java b/测试.java new file mode 100644 index 0000000..6abb25b --- /dev/null +++ b/测试.java @@ -0,0 +1,23 @@ +public class AnimalTest { + public static void main(String[] args) { + // 多态方式创建对象 + Animal dog = new Dog(); + Animal cat = new Cat(); + + // 调用 makeSound 方法(多态体现) + System.out.println("=== 动物叫声测试 ==="); + dog.makeSound(); + cat.makeSound(); + + // 测试 Swimable 接口(Dog 能游泳,Cat 不能) + System.out.println("\n=== 游泳能力测试 ==="); + if (dog instanceof Swimmable) { + ((Swimmable) dog).swim(); + } + if (cat instanceof Swimmable) { + ((Swimmable) cat).swim(); + } else { + System.out.println("小猫不会游泳哦!"); + } + } +} \ No newline at end of file From 7b3994ca84b1b3f59ae158c6582a92453c788a8d Mon Sep 17 00:00:00 2001 From: ZhangJinxuan <2194936226@qq.com> Date: Sun, 19 Apr 2026 19:52:13 +0800 Subject: [PATCH 3/9] =?UTF-8?q?=E6=B7=BB=E5=8A=A0w6=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=A4=B9=E5=8F=8A=E6=89=80=E6=9C=89Java=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- w6 | 1 + 1 file changed, 1 insertion(+) create mode 160000 w6 diff --git a/w6 b/w6 new file mode 160000 index 0000000..3bc4b41 --- /dev/null +++ b/w6 @@ -0,0 +1 @@ +Subproject commit 3bc4b41f0b162e341fd0a8c30f1c4d34c7d6fc00 From 79161d9cd805c4fb7b84b0ef80d25b26f3f9e051 Mon Sep 17 00:00:00 2001 From: ZhangJinxuan <2194936226@qq.com> Date: Sun, 19 Apr 2026 19:59:47 +0800 Subject: [PATCH 4/9] =?UTF-8?q?=E6=B7=BB=E5=8A=A0w4=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=A4=B9=E5=8F=8A=E6=89=80=E6=9C=89=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- w4/面积计算器代码.java | 42 +++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 w4/面积计算器代码.java diff --git a/w4/面积计算器代码.java b/w4/面积计算器代码.java new file mode 100644 index 0000000..2523ed9 --- /dev/null +++ b/w4/面积计算器代码.java @@ -0,0 +1,42 @@ +abstract class Area{ + public abstract double draw(); +} +class circle extends Area{ + double r; + public double draw() { + double area = 3.14 * r * r; + System.out.println(area); + return area; + } +} +class rectangle extends Area{ + double l,b; + public double draw() { + double area = l * b; + System.out.println(area); + return area; + } +} +class tangle extends Area{ + double b,h; + public double draw() { + double area = 0.5 * b * h; + System.out.println(area); + return area; + } +} +public class Main{ + static void main(String[] args) { + circle c=new circle(); + c.r=5; + c.draw(); + rectangle a=new rectangle(); + a.l=5; + a.b=4; + a.draw(); + tangle t=new tangle(); + t.b=5; + t.h=4; + t.draw(); + } +} From e95d7ecd943c8f546b1aad83d30fc79bd8742204 Mon Sep 17 00:00:00 2001 From: ZhangJinxuan <2194936226@qq.com> Date: Mon, 27 Apr 2026 14:20:44 +0800 Subject: [PATCH 5/9] =?UTF-8?q?=E7=AC=AC=E4=B8=80=E6=AC=A1=E6=8F=90?= =?UTF-8?q?=E4=BA=A4=EF=BC=9A=E4=B8=8A=E4=BC=A0w7=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=A4=B9=E6=89=80=E6=9C=89=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ScoreAverge.java | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 ScoreAverge.java diff --git a/ScoreAverge.java b/ScoreAverge.java new file mode 100644 index 0000000..3716739 --- /dev/null +++ b/ScoreAverge.java @@ -0,0 +1,46 @@ +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; + +public class ScoreCalculator { + public static void main(String[] args) { + String fileName = "scores.txt"; + int sum = 0; + int count = 0; + + // try-with-resources 自动关闭流,无需手动写 br.close() + try (BufferedReader br = new BufferedReader(new FileReader(fileName))) { + String line; + while ((line = br.readLine()) != null) { + // 去除字符串前后空格,避免空行或空格影响解析 + line = line.trim(); + if (line.isEmpty()) { + continue; // 跳过空行 + } + + try { + // 解析成绩为整数 + int score = Integer.parseInt(line); + sum += score; + count++; + } catch (NumberFormatException e) { + // 数字格式错误处理 + System.err.println("警告:无法解析成绩 '" + line + "',跳过该数据"); + } + } + + // 计算平均分 + if (count > 0) { + double average = (double) sum / count; + System.out.println("平均分:" + average); + } else { + System.out.println("文件中没有有效成绩数据"); + } + + } catch (IOException e) { + // 文件不存在、读取错误处理 + System.err.println("读取文件时发生错误:" + e.getMessage()); + e.printStackTrace(); + } + } +} \ No newline at end of file From 0d78a67acc8c89d01981757b7ffbdc6b56c16b0f Mon Sep 17 00:00:00 2001 From: ZhangJinxuan <2194936226@qq.com> Date: Tue, 28 Apr 2026 11:34:34 +0800 Subject: [PATCH 6/9] add week8 code --- w8/集合键值转换.java | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 w8/集合键值转换.java diff --git a/w8/集合键值转换.java b/w8/集合键值转换.java new file mode 100644 index 0000000..f97b1e6 --- /dev/null +++ b/w8/集合键值转换.java @@ -0,0 +1,23 @@ +public class Pair{ + private K key; + private V value; + public Pair(K key,V value){ + this.key=key; + this.value=value; + } + public K getKey(){ + return key; + } + public V getValue(){ + return value; + } + public void setKey(K key){ + this.key=key; + } + public void setValue(V value){ + this.value=value; + } + public static Pair swap(Pair pair){ + return new Pair<>(pair.getValue(), pair.getKey()); + } +} \ No newline at end of file From be6b9f8cb7df9c7bc8082c0acc7fc905a26ed9bb Mon Sep 17 00:00:00 2001 From: ZhangJinxuan <2194936226@qq.com> Date: Mon, 11 May 2026 15:57:24 +0800 Subject: [PATCH 7/9] =?UTF-8?q?'=E4=B8=8A=E4=BC=A0=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E7=9A=84=E4=BB=A3=E7=A0=81Article.java=E6=96=87=E4=BB=B6'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Article.java | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 Article.java diff --git a/Article.java b/Article.java new file mode 100644 index 0000000..5e19b06 --- /dev/null +++ b/Article.java @@ -0,0 +1,53 @@ +package com.example.datacollect.model; +import java.util.Date +public class Article { + private String title; + private String url; + private String content; + private String author; + private String Date publishDate; + public Article(String title, String url, String content,String author,Date publishDate) { + this.title = title; + this.url = url; + this.content = content; + this.author = author; + this.publishDate= publishDate; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } + public String getAuthor(){ + return author; + } + public void setAuthor(String author){ + this.author= author; + } + @Override + public String toString() { + return "Article{" + + "title='" + title + '\'' + + ", url='" + url + '\'' + + '}'; + } +} From 911d0fba4c9bc39638c08fc06097e1315e3d1e53 Mon Sep 17 00:00:00 2001 From: ZhangJinxuan <2194936226@qq.com> Date: Mon, 25 May 2026 14:52:44 +0800 Subject: [PATCH 8/9] =?UTF-8?q?=E4=B8=8A=E4=BC=A0w10=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Article.java | 59 ++++++++++++++++++++++++++++++++++++++++++++ HistoryCommmand.java | 17 +++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 Article.java create mode 100644 HistoryCommmand.java diff --git a/Article.java b/Article.java new file mode 100644 index 0000000..358503f --- /dev/null +++ b/Article.java @@ -0,0 +1,59 @@ +package com.example.datacollect.model; +import java.util.Date +public class Article { + private String title; + private String url; + private String content; + private String author; + private Date publishDate; + public Article(String title, String url, String content,String author,Date publishDate) { + this.title = title; + this.url = url; + this.content = content; + this.author = author; + this.publishDate= publishDate; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } + public String getAuthor(){ + return author; + } + public void setAuthor(String author){ + this.author= author; + } + public Date getPublishDate() { + return publishDate; + } + public void setPublishDate(Date publishDate) { + this.publishDate = publishDate; + } + @Override + public String toString() { + return "Article{" + + "title='" + title + '\'' + + ", url='" + url + '\'' + + '}'; + } +} \ No newline at end of file diff --git a/HistoryCommmand.java b/HistoryCommmand.java new file mode 100644 index 0000000..7310ed5 --- /dev/null +++ b/HistoryCommmand.java @@ -0,0 +1,17 @@ +import java.util.ArrayList; +import java.util.List; + +public class HistoryCommand { + // 存储所有输入过的命令 + private final List commandHistory = new ArrayList<>(); + + // 添加命令 + public void addCommand(String cmd) { + commandHistory.add(cmd); + } + + // 获取全部历史 + public List getHistory() { + return new ArrayList<>(commandHistory); // 防御性拷贝,避免外部修改 + } +} \ No newline at end of file From c0904ea4642f2f4948fbdaf5af33b30bd2987b08 Mon Sep 17 00:00:00 2001 From: ZhangJinxuan <2194936226@qq.com> Date: Mon, 25 May 2026 15:05:51 +0800 Subject: [PATCH 9/9] =?UTF-8?q?=E5=90=88=E5=B9=B6=E8=BF=9C=E7=A8=8B?= =?UTF-8?q?=E5=B9=B6=E4=B8=8A=E4=BC=A0excption?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- excption/Repoditory.java | 19 +++++++++++++++++++ excption/excption.java | 7 +++++++ excption/新建 文本文档.txt | 0 3 files changed, 26 insertions(+) create mode 100644 excption/Repoditory.java create mode 100644 excption/excption.java create mode 100644 excption/新建 文本文档.txt diff --git a/excption/Repoditory.java b/excption/Repoditory.java new file mode 100644 index 0000000..d88ea2a --- /dev/null +++ b/excption/Repoditory.java @@ -0,0 +1,19 @@ +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class ArticleRepository { + private static final Logger log = LoggerFactory.getLogger(ArticleRepository.class); + + public void save(Article article) { + // 防御检查:空值拦截 + if (article == null) { + log.warn("保存文章失败:article为空"); + return; + } + if (article.getTitle() == null || article.getTitle().isBlank()) { + log.warn("保存文章失败:标题为空"); + return; + } + // 原有保存逻辑 + } +} \ No newline at end of file diff --git a/excption/excption.java b/excption/excption.java new file mode 100644 index 0000000..506ba6f --- /dev/null +++ b/excption/excption.java @@ -0,0 +1,7 @@ +package exception; + +public class ParseException extends CrawlerException { + public ParseException(String message) { + super(message); + } +} \ No newline at end of file diff --git a/excption/新建 文本文档.txt b/excption/新建 文本文档.txt new file mode 100644 index 0000000..e69de29