From c6717903418cc169398e33e2d40983331a60b480 Mon Sep 17 00:00:00 2001 From: chenhaodong Date: Sun, 22 Dec 2024 18:00:46 +0800 Subject: [PATCH] init --- .idea/.gitignore | 8 + .idea/compiler.xml | 13 + .idea/encodings.xml | 7 + .idea/jarRepositories.xml | 20 ++ .idea/misc.xml | 14 + pom.xml | 29 +++ src/main/java/org/example/Main.java | 246 ++++++++++++++++++ .../java/org/example/model/Satellite.java | 70 +++++ target/classes/org/example/Main.class | Bin 0 -> 7555 bytes .../classes/org/example/model/Satellite.class | Bin 0 -> 1875 bytes 10 files changed, 407 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/compiler.xml create mode 100644 .idea/encodings.xml create mode 100644 .idea/jarRepositories.xml create mode 100644 .idea/misc.xml create mode 100644 pom.xml create mode 100644 src/main/java/org/example/Main.java create mode 100644 src/main/java/org/example/model/Satellite.java create mode 100644 target/classes/org/example/Main.class create mode 100644 target/classes/org/example/model/Satellite.class diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..976c9be --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..aa00ffa --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..712ab9d --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..82dbec8 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..34eb51c --- /dev/null +++ b/pom.xml @@ -0,0 +1,29 @@ + + + 4.0.0 + + org.example + duolaxingqiu + 1.0-SNAPSHOT + + + 8 + 8 + UTF-8 + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 14 + 14 + + + + + + \ No newline at end of file diff --git a/src/main/java/org/example/Main.java b/src/main/java/org/example/Main.java new file mode 100644 index 0000000..b3aa0a1 --- /dev/null +++ b/src/main/java/org/example/Main.java @@ -0,0 +1,246 @@ + + + +package org.example; + +import org.example.model.Satellite; + +import java.util.Scanner; + +import java.util.ArrayList; +import java.util.Scanner; + +public class Main { + private static ArrayList satellites = new ArrayList<>(); + + public static void main(String[] args) { + // 初始化五个卫星对象 + satellites.add(new Satellite("1999-025A", "卫星一号", 7000, true)); + satellites.add(new Satellite("2000-036A", "卫星二号", 8000, false)); + satellites.add(new Satellite("2001-047A", "卫星三号", 9000, true)); + satellites.add(new Satellite("2002-058A", "卫星四号", 10000, false)); + satellites.add(new Satellite("2003-069A", "卫星五号", 11000, true)); + + Scanner scanner = new Scanner(System.in); + displayMenu(); + do { + String choose = scanner.next(); + switch (choose) { + //1-----显示目前活动卫星列表。 + case "1" -> showSatelliteList(); + //2-----注册新卫星。 + case "2" -> addNewSatellite(scanner); + //3-----删除旧卫星。 + case "3" -> delOldSatellite(scanner); + //4-----激活卫星。 + case "4" -> activeSatellite(scanner); + //5-----封锁(失活)卫星。 + case "5" -> blockSatellite(scanner); + //6-----显示失活卫星列表。 + case "6" -> showBlockSatelliteList(); + //7-----按名称模糊查找卫星。 + case "7" -> querySatelliteByNameLike(scanner); + //8-----修改卫星信息。 + case "8" -> modStatelliteInfo(scanner); + //9-----退出! + case "9" -> { + System.out.println("退出"); + System.exit(0); + } + default -> System.out.println("没有这个选项"); + } + + displayMenu(); + } while (scanner.hasNext()); + } + + //1-----显示目前活动卫星列表。 + private static void showSatelliteList() { + for (Satellite satellite : satellites) { + if (satellite.isActivated()) { + System.out.println(satellite); + } + } + } + + //2-----注册新卫星。 + private static void addNewSatellite(Scanner scanner) { + String cosparId = readString(scanner, "请输入卫星的COSPARID: "); + String name = readString(scanner, "请输入卫星的名称: "); + double r = readDouble(scanner, "请输入卫星的半径: "); + boolean activated = readBoolean(scanner, "请输入卫星的状态 (true/false): "); + + Satellite newSatellite = new Satellite(cosparId, name, r, activated); + satellites.add(newSatellite); + System.out.println("卫星已添加: " + newSatellite); + } + + //3-----删除旧卫星。 + private static void delOldSatellite(Scanner scanner) { + String cosparId = readString(scanner, "请输入要删除的卫星COSPARID: "); + boolean flag = false; + for (Satellite se : satellites) { + if (se.getCOSPARID().equals(cosparId)) { + satellites.remove(se); + System.out.println("卫星已删除: " + se); + flag = true; + break; + } + } + if (!flag) { + System.out.println("无效的COSPARID"); + } + } + + //4-----激活卫星。 + private static void activeSatellite(Scanner scanner) { + String cosparId = readString(scanner, "请输入要激活的卫星COSPARID: "); + boolean flag = false; + for (Satellite se : satellites) { + if (se.getCOSPARID().equals(cosparId)) { + if (se.isActivated()) { + System.out.println("卫星已处于激活状态,无需重新激活: " + se); + flag = true; + break; + } + se.setActivated(true); + System.out.println("卫星已激活: " + se); + flag = true; + break; + } + } + if (!flag) { + System.out.println("无效的COSPARID"); + } + } + + //5-----封锁(失活)卫星。 + private static void blockSatellite(Scanner scanner) { + String cosparId = readString(scanner, "请输入要封锁的卫星COSPARID: "); + boolean flag = false; + for (Satellite se : satellites) { + if (se.getCOSPARID().equals(cosparId)) { + if (!se.isActivated()) { + System.out.println("卫星已处于失活状态,无需重新封锁: " + se); + flag = true; + break; + } + se.setActivated(false); + System.out.println("卫星已封锁: " + se); + flag = true; + break; + } + } + if (!flag) { + System.out.println("无效的COSPARID"); + } + } + + //6-----显示失活卫星列表。 + private static void showBlockSatelliteList() { + for (Satellite satellite : satellites) { + if (!satellite.isActivated()) { + System.out.println(satellite); + } + } + } + + //7-----按名称模糊查找卫星。 + private static void querySatelliteByNameLike(Scanner scanner) { + String keyword = readString(scanner, "请输入要查找的卫星名称关键字: "); + for (Satellite satellite : satellites) { + if (satellite.getName().contains(keyword)) { + System.out.println(satellite); + } + } + } + + //8-----修改卫星信息。 + private static void modStatelliteInfo(Scanner scanner) { + String cosparId = readString(scanner, "请输入要修改的卫星COSPARID: "); + boolean flag = false; + for (Satellite se : satellites) { + if (se.getCOSPARID().equals(cosparId)) { + String newCosparId = readString(scanner, "请输入卫星的COSPARID: "); + se.setCOSPARID(newCosparId); + String newName = readString(scanner, "请输入卫星的名称: "); + se.setName(newName); + double newR = readDouble(scanner, "请输入卫星的半径: "); + se.setR(newR); + boolean newActivated = readBoolean(scanner, "请输入卫星的状态 (true/false): "); + se.setActivated(newActivated); + System.out.println("卫星信息已修改: " + se); + flag = true; + break; + } + } + if (!flag) { + System.out.println("无效的COSPARID"); + } + } + + //显示菜单 + public static void displayMenu() { + System.out.println("**************************"); + System.out.println("\t1-----显示目前活动卫星列表。"); + System.out.println("\t2-----注册新卫星。"); + System.out.println("\t3-----删除旧卫星。"); + System.out.println("\t4-----激活卫星。"); + System.out.println("\t5-----封锁(失活)卫星。"); + System.out.println("\t6-----显示失活卫星列表。"); + System.out.println("\t7-----按名称模糊查找卫星。"); + System.out.println("\t8-----修改卫星信息。"); + System.out.println("\t9-----退出!"); + System.out.println("**************************"); + System.out.print("选择:"); + } + + // 读取字符串输入并校验 + private static String readString(Scanner scanner, String prompt) { + String input; + do { + System.out.print(prompt); + input = scanner.next(); + if (input.trim().isEmpty()) { + System.out.println("输入不能为空,请重新输入。"); + } + } while (input.trim().isEmpty()); + return input; + } + + // 读取双精度浮点数输入并校验 + private static double readDouble(Scanner scanner, String prompt) { + double input; + while (true) { + System.out.print(prompt); + if (scanner.hasNextDouble()) { + input = scanner.nextDouble(); + if (input <= 0) { + System.out.println("半径必须大于0,请重新输入。"); + } else { + break; + } + } else { + System.out.println("输入无效,请输入一个数字。"); + scanner.next(); // 清除无效输入 + } + } + return input; + } + + // 读取布尔值输入并校验 + private static boolean readBoolean(Scanner scanner, String prompt) { + boolean input; + while (true) { + System.out.print(prompt); + if (scanner.hasNextBoolean()) { + input = scanner.nextBoolean(); + break; + } else { + System.out.println("输入无效,请输入 true 或 false。"); + scanner.next(); // 清除无效输入 + } + } + return input; + } +} diff --git a/src/main/java/org/example/model/Satellite.java b/src/main/java/org/example/model/Satellite.java new file mode 100644 index 0000000..13f72e3 --- /dev/null +++ b/src/main/java/org/example/model/Satellite.java @@ -0,0 +1,70 @@ +package org.example.model; + +/** + * @author : [chd] + * @version : [v1.0] + * @description : [一句话描述该类的功能] + * @createTime : [2024/12/22 17:27] + * @updateUser : [chd] + * @updateTime : [2024/12/22 17:27] + * @updateRemark : [说明本次修改内容] + */ +public class Satellite { + //卫星id + private String COSPARID; + //卫星名称 + private String name; + //半径 + private double r; + //状态 + private boolean activated=false; + + public Satellite(String COSPARID, String name, double r, boolean activated) { + this.COSPARID = COSPARID; + this.name = name; + this.r = r; + this.activated = activated; + } + + @Override + public String toString() { + return "Satellite{" + + "COSPARID='" + COSPARID + '\'' + + ", name='" + name + '\'' + + ", r=" + r + + ", activated=" + activated + + '}'; + } + + public String getCOSPARID() { + return COSPARID; + } + + public void setCOSPARID(String COSPARID) { + this.COSPARID = COSPARID; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public double getR() { + return r; + } + + public void setR(double r) { + this.r = r; + } + + public boolean isActivated() { + return activated; + } + + public void setActivated(boolean activated) { + this.activated = activated; + } +} diff --git a/target/classes/org/example/Main.class b/target/classes/org/example/Main.class new file mode 100644 index 0000000000000000000000000000000000000000..73f7d5e0d5168b3aec5d2b62eed4713413570574 GIT binary patch literal 7555 zcmb_h3w%`7ng5?;l9@?v0t^HQU>qn&5)$$NLLR&WNH7E>2m*EOkX&HQWG2o`fK+r7 z6nPY|RTKiWLW>TdB7&QQpwO;$w`=R_KHF-yk8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