From 229737483dc66bab6c4bfa821bd0ccbd1d1b1671 Mon Sep 17 00:00:00 2001 From: LiuZihan <1353843969@qq.com> Date: Fri, 22 May 2026 15:25:08 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=20'project1/Main.java'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- project1/Main.java | 71 ---------------------------------------------- 1 file changed, 71 deletions(-) delete mode 100644 project1/Main.java diff --git a/project1/Main.java b/project1/Main.java deleted file mode 100644 index 45a6b31..0000000 --- a/project1/Main.java +++ /dev/null @@ -1,71 +0,0 @@ -package com.example; - -import com.example.bean.Movie; -import com.example.crawler.MovieCrawler; -import com.example.chart.DrawChart; -import java.io.FileWriter; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - -public class Main { - public static void main(String[] args) { - - // 1. 爬取数据 - MovieCrawler crawler = new MovieCrawler(); - List movies = crawler.start(); - - // 2. 数据清洗 - List cleanData = new ArrayList<>(); - for (Movie movie : movies) { - if (movie.getTitle() != null && !movie.getTitle().isBlank()) { - cleanData.add(movie); - } - } - - // ===================== CSV 保存功能 恢复!===================== - try (FileWriter writer = new FileWriter("movie_top100.csv")) { - writer.write("电影名称,评分,导演,上映年份\n"); - for (Movie m : cleanData) { - writer.write(m.getTitle() + "," + m.getScore() + "," + m.getDirector() + "," + m.getYear() + "\n"); - } - System.out.println("✅ CSV 文件已保存:movie_top100.csv"); - } catch (Exception e) { - e.printStackTrace(); - } - // ============================================================== - - // 3. 评分统计 - Map scoreCount = cleanData.stream() - .collect(Collectors.groupingBy(Movie::getScore, Collectors.counting())); - - // 4. 控制台打印表格 - System.out.println("\n=========================================="); - System.out.println(" 电影评分统计表格 "); - System.out.println("=========================================="); - System.out.printf("%-10s %-10s %-10s%n", "评分", "数量(部)", "占比(%)"); - System.out.println("------------------------------------------"); - - double total = cleanData.size(); - for (Map.Entry entry : scoreCount.entrySet()) { - String score = entry.getKey(); - long count = entry.getValue(); - double rate = (count * 100.0) / total; - System.out.printf("%-12s %-12d %-10.2f%n", score, count, rate); - } - - System.out.println("------------------------------------------"); - System.out.printf("总计:%d 部电影%n", (long) total); - System.out.println("=========================================="); - - // 5. 生成正常折线图:按排名 1→100 顺序连线 - List scoreList = new ArrayList<>(); - for (Movie movie : cleanData) { - scoreList.add(Double.parseDouble(movie.getScore())); - } - - DrawChart drawing = new DrawChart(); - drawing.drawByOrder(scoreList); - } -} \ No newline at end of file